GitHub Action Manage Stale PRs - SSWConsulting/SSW.Rules.Content GitHub Wiki

This GitHub Action helps manage the lifecycle of pull requests by automatically labeling PRs based on age and flagging those that may be suffering from merge debt. Itโ€™s part of SSWโ€™s standard pull request workflow.

When It Runs

  • On PR opened or marked โ€œready for reviewโ€, if it's targeting the main branch
  • Every 2 hours
  • Manually, using the "Run workflow" button in GitHub

What It Does

On PR Creation (pull_request)

  • When a new PR is opened or marked ready:

    • Checks if it's not cross-repository

    • Applies the label:
      Age: ๐Ÿฅš - New (i.e. "about 2 hours old")

This gives the PR an initial "age" label as a starting point.

๐Ÿ•‘ On Schedule (cron)

Every 2 hours, the workflow will:

  1. Ensure labels exist for the following age groups:

    • ๐Ÿฅš New โ€“ 2 hours

    • ๐Ÿฃ Young โ€“ 4 hours

    • ๐Ÿฅ Adolescent โ€“ 8 hours

    • ๐Ÿค Mature โ€“ 16 hours

    • ๐Ÿ“ Old โ€“ 32 hours

    • ๐Ÿ— Ancient โ€“ 64 hours

    • ๐Ÿฆ– Extinct โ€“ 128+ hours

  2. Loop through all open PRs

    • Calculates how many hours old each PR is

    • Applies the appropriate age label

    • Removes any other age labels

  3. Add โ€œMerge Debtโ€ label & comment if needed

    • If a PR is over 36 hours old

    • And the author is not a bot

    • And it doesnโ€™t already have a "๐Ÿ”ฅ Merge Debt" label
      โ†’ Then it:

      • Adds the ๐Ÿ”ฅ Merge Debt label

      • Posts a friendly comment reminding the author to take action:

        "This PR has been here a while... Please action (e.g. get a review) and merge or close."