Skip to content

Commit

Permalink
add ability to select issues or prs for closing
Browse files Browse the repository at this point in the history
  • Loading branch information
kdaily committed Sep 15, 2020
1 parent fd3a22f commit f3138fe
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,22 @@ Here's an abbreviated example with just the step for this action:
steps:
- uses: aws-actions/stale-issue-cleanup@v3
with:
# Types of issues that will be processed
issue-types: issues,pull_requests

# Messages this action will apply to issues
stale-issue-message: Stale issue message
stale-pr-message: Stale issue message
ancient-issue-message: Stale issue message

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

# Issue timing and upvote counting
days-before-stale: 4
days-before-close: 7
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
repo-token:
description: 'Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
required: true
issue-types:
description: 'Issue types to process ("issues", "pull_requests", or "issues,pull_requests")'
default: 'issues,pull_requests'
stale-issue-message:
description: 'The message to post on the issue when tagging it. If none provided, will not mark issues stale.'
stale-pr-message:
Expand Down Expand Up @@ -50,6 +53,7 @@ runs:
image: 'Dockerfile'
env:
REPO_TOKEN: ${{ inputs.repo-token }}
ISSUE_TYPES: ${{ inputs.issue-types }}
ANCIENT_ISSUE_MESSAGE: ${{ inputs.ancient-issue-message }}
ANCIENT_PR_MESSAGE: ${{ inputs.ancient-pr-message }}
STALE_ISSUE_MESSAGE: ${{ inputs.stale-issue-message }}
Expand Down
16 changes: 16 additions & 0 deletions src/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getAndValidateInputs() {
stalePrLabel: process.env.STALE_PR_LABEL,
exemptPrLabels: process.env.EXEMPT_PR_LABELS,
cfsLabel: process.env.CFS_LABEL,
issueTypes: process.env.ISSUE_TYPES.split(","),
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
dryrun: String(process.env.DRYRUN).toLowerCase() === 'true',
Expand Down Expand Up @@ -72,6 +73,21 @@ async function processIssues(client, args) {
log.debug(`ISSUE #${issue.number}: ${issue.title}`);
log.debug(`last updated ${issue.updated_at}`);
const isPr = 'pull_request' in issue ? true : false;
const skip_pull_requests = args.issueTypes.indexOf(`pull_requests`) == -1;
const skip_issues = args.issueTypes.indexOf(`issues`) == -1

if (isPr && skip_pull_requests) {
// If record is a pull request but pull requests weren't configured
log.debug(`Issue is a pull request, which are excluded`);
return;
}

if ((!isPr) && skip_issues) {
// If record is an issue but issues weren't configured
log.debug(`Issue is an issue, which are excluded`);
return;
}


const staleMessage = isPr ? args.stalePrMessage : args.staleIssueMessage;
/*
Expand Down
1 change: 1 addition & 0 deletions test/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ EXEMPT_PR_LABELS=go-away-bot
RESPONSE_REQUESTED_LABEL=response-requested
CFS_LABEL=closed-for-staleness
MINIMUM_UPVOTES_TO_EXEMPT=1
ISSUE_TYPES=issues,pull_requests
2 changes: 2 additions & 0 deletions test/entrypoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('GitHub issue parser', () => {
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
cfsLabel: process.env.CFS_LABEL,
issueTypes: process.env.ISSUE_TYPES.split(","),
});
});

Expand Down Expand Up @@ -89,6 +90,7 @@ describe('GitHub issue parser', () => {
process.env.ANCIENT_ISSUE_MESSAGE = '';
process.env.STALE_ISSUE_MESSAGE = '';
process.env.STALE_PR_MESSAGE = '';
process.env.ISSUE_TYPES = "issues,pull_requests";
await run();
process.env.STALE_ISSUE_MESSAGE = process.env.STALE_ISSUE_MESSAGE;
process.env.ANCIENT_ISSUE_MESSAGE = OLD_ENV.ANCIENT_ISSUE_MESSAGE;
Expand Down
1 change: 1 addition & 0 deletions test/local-docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CFS_LABEL=closed-for-staleness
MINIMUM_UPVOTES_TO_EXEMPT=1
DRYRUN=true
LOGLEVEL=DEBUG
ISSUE_TYPES=issues,pull_requests

# Change this to the repo you're testing
GITHUB_REPOSITORY=octocat/Hello-World
Expand Down

0 comments on commit f3138fe

Please sign in to comment.