name: manage labels from comments

on: [issue_comment]

jobs:
  manage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v7
        if: ${{ contains(github.event.comment.body, '/notstale') }}
        with:
          script: |
            github.rest.issues.removeLabel({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number:context.issue.number,
              name: "stale",
            });
      - uses: actions/github-script@v7
        if: ${{ !github.event.issue.pull_request && contains(github.event.comment.body, '/notexpired') }}
        with:
          script: |
            github.rest.issues.update({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              state: "open",
            });
      - uses: actions/github-script@v7
        if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/notexpired') }}
        with:
          script: |
            github.rest.pulls.update({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number,
              state: "open",
            });
      - uses: actions/github-script@v7
        if: ${{ contains(github.event.comment.body, '/notexpired') }}
        with:
          script: |
            github.rest.issues.removeLabel({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              name: "stale",
            });
            github.rest.issues.removeLabel({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              name: "expired",
            });
