Skip to content

Commit

Permalink
feature: support dry run
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertk committed Apr 16, 2020
1 parent bbe5a15 commit 6ba614f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ inputs:
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:
description: 'Set to true to not perform repository changes'

runs:
using: 'docker'
Expand All @@ -63,3 +65,4 @@ runs:
CLOSED_FOR_STALENESS_LABEL: ${{ inputs.closed-for-staleness-label }}
MINIMUM_UPVOTES_TO_EXEMPT: ${{ inputs.minimum-upvotes-to-exempt }}
LOGLEVEL: ${{ inputs.loglevel }}
DRYRUN: ${{ inputs.dry-run }}
2 changes: 2 additions & 0 deletions sample_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ jobs:

repo-token: ${{ secrets.GITHUB_TOKEN }}
#loglevel: DEBUG
# Set dry-run to true to not perform label or close actions.
#dry-run: true
47 changes: 39 additions & 8 deletions src/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function getAndValidateInputs() {
exemptPrLabel: process.env.EXEMPT_PR_LABEL,
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
dryrun: !!process.env.DRYRUN,
};

for (const numberInput of [
Expand Down Expand Up @@ -93,14 +94,26 @@ async function processIssues(client, args) {
lastCommentTime + MS_PER_DAY * args.daysBeforeClose
);
if (lastCommentTime > staleLabelTime) {
log.debug(`issue was commented on after the label was applied`);
await removeLabel(client, issue, staleLabel);
await removeLabel(client, issue, responseRequestedLabel);
log.debug('issue was commented on after the label was applied');
if (args.dryrun) {
log.info(
`dry run: would remove ${staleLabel} and ${responseRequestedLabel} labels for ${issue.number}`
);
} else {
await removeLabel(client, issue, staleLabel);
await removeLabel(client, issue, responseRequestedLabel);
}
} else {
if (currentTime > sTime) {
log.debug(`time expired on this issue, need to close it`);
await removeLabel(client, issue, staleLabel);
await closeIssue(client, issue);
if (args.dryrun) {
log.info(
`dry run: would remove ${staleLabel} for ${issue.number} and close`
);
} else {
await removeLabel(client, issue, staleLabel);
await closeIssue(client, issue);
}
} else {
// else ignore it because we need to wait longer before closing
log.debug(`${currentTime} is less than ${sTime}, doing nothing`);
Expand All @@ -117,11 +130,23 @@ async function processIssues(client, args) {
);
if (lastUpdateTme > rrLabelTime) {
log.debug(`issue was commented on after the label was applied`);
await removeLabel(client, issue, responseRequestedLabel);
if (args.dryrun) {
log.info(
`dry run: would remove ${responseRequestedLabel} from ${issue.number}`
);
} else {
await removeLabel(client, issue, responseRequestedLabel);
}
} else {
if (currentTime >= rrTime) {
log.debug(`time expired on this issue, need to label it stale`);
await markStale(client, issue, staleMessage, staleLabel);
if (args.dryrun) {
log.info(
`dry run: would mark ${issue.number} as ${staleLabel} due to ${responseRequestedLabel} age`
);
} else {
await markStale(client, issue, staleMessage, staleLabel);
}
} else {
// else ignore it because we need to wait longer before staleing
log.debug(`${currentTime} is less than ${rrTime}, doing nothing`);
Expand All @@ -142,7 +167,13 @@ async function processIssues(client, args) {
log.debug('issue is ancient but has enough upvotes to exempt');
} else {
log.debug('issue is ancient and not enough upvotes; marking stale');
await markStale(client, issue, ancientMessage, staleLabel);
if (args.dryrun) {
log.info(
`dry run: would mark ${issue.number} as ${staleLabel} due to last updated age`
);
} else {
await markStale(client, issue, ancientMessage, staleLabel);
}
}
}
}
Expand Down

0 comments on commit 6ba614f

Please sign in to comment.