Skip to content

Commit

Permalink
Add support for multiple exempt labels
Browse files Browse the repository at this point in the history
  • Loading branch information
debora-ito committed Sep 3, 2020
1 parent d50cebc commit c5f9ce7
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 36 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ This workflow file [follows the standard workflow syntax for Github Actions.](ht

A sample workflow file for you to use as a drop-in is in [sample_workflow.yml](./sample_workflow.yml).

For a list of options and their description, see [action.yml](./action.yml).

Here's an abbreviated example with just the step for this action:

```yaml
Expand All @@ -54,9 +56,9 @@ steps:

# Labels this action will apply to issues
stale-issue-label: closing-soon
exempt-issue-label: awaiting-approval
exempt-issue-labels: awaiting-approval
stale-pr-label: no-pr-activity
exempt-pr-label: awaiting-approval
exempt-pr-labels: awaiting-approval
response-requested-label: response-requested
closed-for-staleness-label: closed-for-staleness

Expand Down
32 changes: 16 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@ inputs:
stale-pr-message:
description: 'The message to post on the pr when tagging it. If none provided, will not mark pull requests stale.'
days-before-stale:
description: 'The number of days old an issue can be before marking it stale'
description: 'The number of days old an issue can be before marking it stale.'
default: 60
days-before-close:
description: 'The number of days to wait to close an issue or pull request after it being marked stale'
description: 'The number of days to wait to close an issue or pull request after it being marked stale.'
default: 7
stale-issue-label:
description: 'The label to apply when an issue is stale'
description: 'The label to apply when an issue is stale.'
default: 'Stale'
exempt-issue-label:
description: 'The label to apply when an issue is exempt from being marked stale'
exempt-issue-labels:
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
stale-pr-label:
description: 'The label to apply when a pull request is stale'
description: 'The label to apply when a pull request is stale.'
default: 'Stale'
exempt-pr-label:
description: 'The label to apply when a pull request is exempt from being marked stale'
exempt-pr-labels:
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
ancient-issue-message:
description: 'The label to apply when an issue is very old'
description: 'The message to post when an issue is very old.'
ancient-pr-message:
description: 'The label to apply when a pr is very old'
description: 'The message to post when a pr is very old.'
days-before-ancient:
description: 'The number of days old an issue can be before marking it ancient'
description: 'The number of days old an issue can be before marking it ancient.'
default: 360
response-requested-label:
description: 'The label that gets applied when a response is requested'
description: 'The label that gets applied when a response is requested.'
closed-for-staleness-label:
description: 'The label that gets applied when an issue is closed for staleness'
description: 'The label that gets applied when an issue is closed for staleness.'
minimum-upvotes-to-exempt:
description: 'The minimum number of "upvotes" that an issue needs to have before not marking as ancient'
description: 'The minimum number of "upvotes" that an issue needs to have before not marking as ancient.'
loglevel:
description: 'Set to DEBUG to enable debug logging'
dry-run:
Expand All @@ -58,9 +58,9 @@ runs:
DAYS_BEFORE_CLOSE: ${{ inputs.days-before-close }}
DAYS_BEFORE_ANCIENT: ${{ inputs.days-before-ancient }}
STALE_ISSUE_LABEL: ${{ inputs.stale-issue-label }}
EXEMPT_ISSUE_LABEL: ${{ inputs.exempt-issue-label }}
EXEMPT_ISSUE_LABELS: ${{ inputs.exempt-issue-labels }}
STALE_PR_LABEL: ${{ inputs.stale-pr-label }}
EXEMPT_PR_LABEL: ${{ inputs.exempt-pr-label }}
EXEMPT_PR_LABELS: ${{ inputs.exempt-pr-labels }}
RESPONSE_REQUESTED_LABEL: ${{ inputs.response-requested-label }}
CFS_LABEL: ${{ inputs.closed-for-staleness-label }}
MINIMUM_UPVOTES_TO_EXEMPT: ${{ inputs.minimum-upvotes-to-exempt }}
Expand Down
4 changes: 2 additions & 2 deletions sample_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:

# These labels are required
stale-issue-label: closing-soon
exempt-issue-label: awaiting-approval
exempt-issue-labels: awaiting-approval
stale-pr-label: no-pr-activity
exempt-pr-label: awaiting-approval
exempt-pr-labels: awaiting-approval
response-requested-label: response-requested

# Don't set this to not apply a label when closing issues
Expand Down
23 changes: 13 additions & 10 deletions src/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
getLastCommentTime,
asyncForEach,
dateFormatToIsoUtc,
parseCommaSeparatedString,
} = require('./utils.js');

const MS_PER_DAY = 86400000;
Expand All @@ -34,9 +35,9 @@ function getAndValidateInputs() {
daysBeforeClose: parseFloat(process.env.DAYS_BEFORE_CLOSE),
daysBeforeAncient: parseFloat(process.env.DAYS_BEFORE_ANCIENT),
staleIssueLabel: process.env.STALE_ISSUE_LABEL,
exemptIssueLabel: process.env.EXEMPT_ISSUE_LABEL,
exemptIssueLabels: process.env.EXEMPT_ISSUE_LABELS,
stalePrLabel: process.env.STALE_PR_LABEL,
exemptPrLabel: process.env.EXEMPT_PR_LABEL,
exemptPrLabels: process.env.EXEMPT_PR_LABELS,
cfsLabel: process.env.CFS_LABEL,
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
Expand Down Expand Up @@ -81,18 +82,20 @@ async function processIssues(client, args) {
const ancientMessage = args.ancientIssueMessage;

const staleLabel = isPr ? args.stalePrLabel : args.staleIssueLabel;
const exemptLabel = isPr ? args.exemptPrLabel : args.exemptIssueLabel;
const responseRequestedLabel = isPr
? args.responseRequestedLabel
: args.responseRequestedLabel;
const exemptLabels = parseCommaSeparatedString(isPr ? args.exemptPrLabels : args.exemptIssueLabels);
const responseRequestedLabel = isPr ? args.responseRequestedLabel : args.responseRequestedLabel;

const issueTimelineEvents = await getTimelineEvents(client, issue);
const currentTime = new Date(Date.now());
if (exemptLabel && isLabeled(issue, exemptLabel)) {
// If issue contains exempt label, do nothing
log.debug(`issue contains exempt label`);
return;

if (exemptLabels &&
exemptLabels.some((s) => isLabeled(issue, s))
) {
// If issue contains exempt label, do nothing
log.debug(`issue contains exempt label`);
return;
}

if (isLabeled(issue, staleLabel)) {
log.debug(`issue contains the stale label`);
const lastCommentTime = getLastCommentTime(issueTimelineEvents);
Expand Down
11 changes: 11 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,15 @@ module.exports.asyncForEach = async (array, callback) => {
*/
module.exports.dateFormatToIsoUtc = (dateTime) => {
return dateFormat(dateTime, "isoUtcDateTime");
};

/**
* Splits a string `s` into an array of substrings, using
* a comma as a separator
* @param {String} s
* @return {Array} Array of strings
*/
module.exports.parseCommaSeparatedString = (s) => {
if (!s.length) return [];
return s.split(',').map(l => l.trim());
};
4 changes: 2 additions & 2 deletions test/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ DAYS_BEFORE_STALE=0.05
DAYS_BEFORE_CLOSE='0.06'
DAYS_BEFORE_ANCIENT='1'
STALE_ISSUE_LABEL=closing-soon
EXEMPT_ISSUE_LABEL=go-away-bot
EXEMPT_ISSUE_LABELS=go-away-bot
STALE_PR_LABEL=stale-pr
EXEMPT_PR_LABEL=go-away-bot
EXEMPT_PR_LABELS=go-away-bot
RESPONSE_REQUESTED_LABEL=response-requested
CFS_LABEL=closed-for-staleness
MINIMUM_UPVOTES_TO_EXEMPT=1
Loading

0 comments on commit c5f9ce7

Please sign in to comment.