/lock-threads

GitHub Action that locks closed issues and pull requests after a period of inactivity

Primary LanguageJavaScriptMIT LicenseMIT

Lock Threads

Lock Threads is a GitHub Action that locks closed issues and pull requests after a period of inactivity.

The legacy version of this project can be found here.

Supporting the Project

The continued development of Lock Threads is made possible thanks to the support of awesome backers. If you'd like to join them, please consider contributing with Patreon, PayPal or Bitcoin.

Usage

Create a lock.yml workflow file in the .github/workflows directory, use one of the example workflows to get started.

Inputs

The action can be configured using input parameters. All parameters are optional, except github-token.

  • github-token
    • GitHub access token, value must be ${{ github.token }}
    • Required
  • issue-lock-inactive-days
    • Number of days of inactivity before a closed issue is locked
    • Optional, defaults to 365
  • issue-exclude-created-before
    • Do not lock issues created before a given timestamp, value must follow ISO 8601
    • Optional, defaults to ''
  • issue-exclude-labels
    • Do not lock issues with these labels, value must be a comma separated list of labels or ''
    • Optional, defaults to ''
  • issue-lock-labels
    • Labels to add before locking an issue, value must be a comma separated list of labels or ''
    • Optional, defaults to ''
  • issue-lock-comment
    • Comment to post before locking an issue
    • Optional, defaults to ''
  • issue-lock-reason
    • Reason for locking an issue, value must be one of resolved, off-topic, too heated, spam or ''
    • Optional, defaults to resolved
  • pr-lock-inactive-days
    • Number of days of inactivity before a closed pull request is locked
    • Optional, defaults to 365
  • pr-exclude-created-before
    • Do not lock pull requests created before a given timestamp, value must follow ISO 8601
    • Optional, defaults to ''
  • pr-exclude-labels
    • Do not lock pull requests with these labels, value must be a comma separated list of labels or ''
    • Optional, defaults to ''
  • pr-lock-labels
    • Labels to add before locking a pull request, value must be a comma separated list of labels or ''
    • Optional, defaults to ''
  • pr-lock-comment
    • Comment to post before locking a pull request
    • Optional, defaults to ''
  • pr-lock-reason
    • Reason for locking a pull request, value must be one of resolved, off-topic, too heated, spam or ''
    • Optional, defaults to resolved
  • process-only
    • Limit locking to only issues or pull requests, value must be one of issues, prs or ''
    • Optional, defaults to ''

Outputs

  • issues
    • Issues that have been locked, value is a JSON string in the form of [{"owner": "actions", "repo": "toolkit", "issue_number": 1}]
    • Defaults to ''
  • prs
    • Pull requests that have been locked, value is a JSON string in the form of [{"owner": "actions", "repo": "toolkit", "issue_number": 1}]
    • Defaults to ''

Examples

The following workflow will search once an hour for closed issues and pull requests that can be locked.

name: 'Lock threads'

on:
  schedule:
    - cron: '0 * * * *'

jobs:
  lock:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/lock-threads@v2
        with:
          github-token: ${{ github.token }}

Edit the workflow after the initial backlog of issues and pull requests has been processed to reduce the frequency of scheduled runs. Running the workflow only once a day helps reduce resource usage.

on:
  schedule:
    - cron: '0 0 * * *'

Available input parameters

This workflow declares all the available input parameters of the action and their default values. Any of the parameters can be omitted, except github-token.

name: 'Lock threads'

on:
  schedule:
    - cron: '0 0 * * *'

jobs:
  lock:
    runs-on: ubuntu-latest
    steps:
      - uses: dessant/lock-threads@v2
        with:
          github-token: ${{ github.token }}
          issue-lock-inactive-days: '365'
          issue-exclude-created-before: ''
          issue-exclude-labels: ''
          issue-lock-labels: ''
          issue-lock-comment: ''
          issue-lock-reason: 'resolved'
          pr-lock-inactive-days: '365'
          pr-exclude-created-before: ''
          pr-exclude-labels: ''
          pr-lock-labels: ''
          pr-lock-comment: ''
          pr-lock-reason: 'resolved'
          process-only: ''

Excluding issues and pull requests

This step will lock only issues, and exclude issues created before 2018, or those with the upstream or help-wanted labels applied.

    steps:
      - uses: dessant/lock-threads@v2
        with:
          github-token: ${{ github.token }}
          issue-exclude-created-before: '2018-01-01T00:00:00Z'
          issue-exclude-labels: 'upstream, help-wanted'
          process-only: 'issues'

This step will lock only pull requests, and exclude those with the wip label applied.

    steps:
      - uses: dessant/lock-threads@v2
        with:
          github-token: ${{ github.token }}
          pr-exclude-labels: 'wip'
          process-only: 'prs'

Commenting and labeling

This step will post a comment on issues and pull requests before locking them, and apply the outdated label to issues.

    steps:
      - uses: dessant/lock-threads@v2
        with:
          github-token: ${{ github.token }}
          issue-lock-labels: 'outdated'
          issue-lock-comment: >
            This issue has been automatically locked since there
            has not been any recent activity after it was closed.
            Please open a new issue for related bugs.
          pr-lock-comment: >
            This pull request has been automatically locked since there
            has not been any recent activity after it was closed.
            Please open a new issue for related bugs.

How are issues and pull requests determined to be inactive?

The action uses GitHub's updated search qualifier to determine inactivity. Any change to an issue or pull request is considered an update, including comments, changing labels, applying or removing milestones, or pushing commits.

An easy way to check and see which issues or pull requests will initially be locked is to add the updated search qualifier to either the issue or pull request page filter for your repository: is:closed is:unlocked updated:<2018-12-20. Adjust the date to be 365 days ago (or whatever you set for *-lock-inactive-days) to see which issues or pull requests will be locked.

Why are only some issues and pull requests processed?

To avoid triggering abuse prevention mechanisms on GitHub, only 50 issues and pull requests will be handled at once. If your repository has more than that, it will just take a few hours or days to process them all.

License

Copyright (c) 2017-2020 Armin Sebastian

This software is released under the terms of the MIT License. See the LICENSE file for further information.