Skip to content

Commit

Permalink
Added environment variable/argument use-created-date-for-ancient whic…
Browse files Browse the repository at this point in the history
…h if set to true uses issue created date instead of modified date for determining an ancient issue. (#151)

* Added environment variable/argument use-created-date-for-ancient which if set to true uses issue created date instead of modified date for determining an ancient issue.

* Modified test to include new environment variable USE_CREATED_DATE_FOR_ANCIENT.
  • Loading branch information
ashishdhingra authored Aug 19, 2022
1 parent 04aedba commit eb0313c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ inputs:
description: 'Set to DEBUG to enable debug logging'
dry-run:
description: 'Set to true to not perform repository changes'
use-created-date-for-ancient:
description: 'Set to true to use issue created date instead of modified date for determining an ancient issue.'

runs:
using: 'docker'
Expand All @@ -70,3 +72,4 @@ runs:
MINIMUM_UPVOTES_TO_EXEMPT: ${{ inputs.minimum-upvotes-to-exempt }}
LOGLEVEL: ${{ inputs.loglevel }}
DRYRUN: ${{ inputs.dry-run }}
USE_CREATED_DATE_FOR_ANCIENT: ${{ inputs.use-created-date-for-ancient }}
66 changes: 39 additions & 27 deletions src/entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function getAndValidateInputs() {
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
dryrun: String(process.env.DRYRUN).toLowerCase() === 'true',
useCreatedDateForAncient: String(process.env.USE_CREATED_DATE_FOR_ANCIENT).toLowerCase() === 'true'
};

for (const numberInput of [
Expand Down Expand Up @@ -204,38 +205,49 @@ async function processIssues(client, args) {
);
}
}
} else if (
Date.parse(issue.updated_at) <
new Date(Date.now() - MS_PER_DAY * args.daysBeforeAncient)
) {
if (typeof args.minimumUpvotesToExempt !== 'undefined') {
if (
await hasEnoughUpvotes(
client,
issue.number,
args.minimumUpvotesToExempt
)
) {
log.debug('issue is ancient but has enough upvotes to exempt');
} else {
const dateToCompare = (args.useCreatedDateForAncient ? Date.parse(issue.created_at) : Date.parse(issue.updated_at));
log.debug(`using issue ${args.useCreatedDateForAncient ? "created date" : "last updated"} to determine if the issue is ancient.`);
if (
dateToCompare < new Date(Date.now() - MS_PER_DAY * args.daysBeforeAncient)
) {
if (typeof args.minimumUpvotesToExempt !== 'undefined') {
if (
await hasEnoughUpvotes(
client,
issue.number,
args.minimumUpvotesToExempt
)
) {
log.debug('issue is ancient but has enough upvotes to exempt');
} else {
log.debug('issue is ancient and not enough upvotes; marking stale');
if (ancientMessage) {
if (args.dryrun) {
log.info(
`dry run: would mark #${issue.number} as ${staleLabel} due to ${args.useCreatedDateForAncient ? "created date" : "last updated"} age`
);
} else {
await markStale(client, issue, ancientMessage, staleLabel);
}
} else {
log.debug(`ancient message is null/empty, doing nothing`);
}
}
} else {
log.debug('issue is ancient and not enough upvotes; marking stale');
if (args.dryrun) {
log.info(
`dry run: would mark #${issue.number} as ${staleLabel} due to last updated age`
);
if (ancientMessage) {
if (args.dryrun) {
log.info(
`dry run: would mark #${issue.number} as ${staleLabel} due to ${args.useCreatedDateForAncient ? "created date" : "last updated"} age`
);
} else {
await markStale(client, issue, ancientMessage, staleLabel);
}
} else {
await markStale(client, issue, ancientMessage, staleLabel);
log.debug(`ancient message is null/empty, doing nothing`);
}
}
} else {
log.debug('issue is ancient and not enough upvotes; marking stale');
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
3 changes: 2 additions & 1 deletion src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ module.exports.getIssues = async (client, args) => {
}

if (args.ancientIssueMessage && args.ancientIssueMessage !== '') {
log.debug(`using issue ${args.useCreatedDateForAncient ? "created date" : "last updated"} to determine for getting ancient issues.`);
options = client.issues.listForRepo.endpoint.merge({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
Expand All @@ -144,7 +145,7 @@ module.exports.getIssues = async (client, args) => {
const ancientResults = await client.paginate(options);
ancientIssues = ancientResults.filter(
(issue) =>
new Date(issue.updated_at) <
(args.useCreatedDateForAncient ? new Date(issue.created_at) : new Date(issue.updated_at)) <
new Date(Date.now() - MS_PER_DAY * args.daysBeforeAncient)
);
log.debug(`found ${ancientIssues.length} ancient issues`);
Expand Down
1 change: 1 addition & 0 deletions test/entrypoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('GitHub issue parser', () => {
minimumUpvotesToExempt: parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT),
cfsLabel: process.env.CFS_LABEL,
issueTypes: process.env.ISSUE_TYPES.split(","),
useCreatedDateForAncient: !!process.env.USE_CREATED_DATE_FOR_ANCIENT
});
});

Expand Down

0 comments on commit eb0313c

Please sign in to comment.