Skip to content

Commit

Permalink
fix: docker action conversion, no more env key
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertk committed Jan 23, 2025
1 parent c452909 commit 941c747
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 37 deletions.
20 changes: 0 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,3 @@ inputs:
runs:
using: 'node20'
main: 'dist/index.js'
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 }}
STALE_PR_MESSAGE: ${{ inputs.stale-pr-message }}
DAYS_BEFORE_STALE: ${{ inputs.days-before-stale }}
DAYS_BEFORE_CLOSE: ${{ inputs.days-before-close }}
DAYS_BEFORE_ANCIENT: ${{ inputs.days-before-ancient }}
STALE_ISSUE_LABEL: ${{ inputs.stale-issue-label }}
EXEMPT_ISSUE_LABELS: ${{ inputs.exempt-issue-labels }}
STALE_PR_LABEL: ${{ inputs.stale-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 }}
LOGLEVEL: ${{ inputs.loglevel }}
DRYRUN: ${{ inputs.dry-run }}
USE_CREATED_DATE_FOR_ANCIENT: ${{ inputs.use-created-date-for-ancient }}
31 changes: 30 additions & 1 deletion src/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ export type Inputs = {
};

export function getAndValidateInputs(): Inputs {
// Previous versions of this action were Docker-based an used a runs.evn
// key to pass inputs. This is not supported in JS actions. This workaround
// reexports the inputs from the environment variables.
for (const env of [
'INPUT_REPO_TOKEN',
'INPUT_ISSUE_TYPES',
'INPUT_ANCIENT_ISSUE_MESSAGE',
'INPUT_ANCIENT_PR_MESSAGE',
'INPUT_STALE_ISSUE_MESSAGE',
'INPUT_STALE_PR_MESSAGE',
'INPUT_DAYS_BEFORE_STALE',
'INPUT_DAYS_BEFORE_CLOSE',
'INPUT_DAYS_BEFORE_ANCIENT',
'INPUT_STALE_ISSUE_LABEL',
'INPUT_EXEMPT_ISSUE_LABELS',
'INPUT_STALE_PR_LABEL',
'INPUT_EXEMPT_PR_LABELS',
'INPUT_CLOSED_FOR_STALENESS_LABEL',
'INPUT_RESPONSE_REQUESTED_LABEL',
'INPUT_MINIMUM_UPVOTES_TO_EXEMPT',
'INPUT_DRYRUN',
'INPUT_LOGLEVEL',
'INPUT_USE_CREATED_DATE_FOR_ANCIENT',
]) {
if (process.env[env]) {
core.exportVariable(env.split('INPUT_')[1], process.env[env]);
}
}
// End workaround
const args = {
repoToken: process.env.REPO_TOKEN ?? '',
ancientIssueMessage: process.env.ANCIENT_ISSUE_MESSAGE ?? '',
Expand All @@ -46,7 +75,7 @@ export function getAndValidateInputs(): Inputs {
exemptIssueLabels: process.env.EXEMPT_ISSUE_LABELS ?? '',
stalePrLabel: process.env.STALE_PR_LABEL ?? '',
exemptPrLabels: process.env.EXEMPT_PR_LABELS ?? '',
cfsLabel: process.env.CFS_LABEL ?? '',
cfsLabel: process.env.CLOSED_FOR_STALENESS_LABEL ?? '',
issueTypes: (process.env.ISSUE_TYPES ?? '').split(','),
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL ?? '',
minimumUpvotesToExempt: Number.parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT ?? '0'),
Expand Down
8 changes: 7 additions & 1 deletion src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export async function hasEnoughUpvotes(
// The squirrel-girl preview is no longer needed in newer versions
per_page: 100,
});
const upvotes = reactions.reduce((acc, cur) => (cur.content.match(/\+1|heart|hooray|rocket/) ? acc + 1 : acc), 0);
const upvotes = reactions.filter(
(reaction) =>
reaction.content === '+1' ||
reaction.content === 'heart' ||
reaction.content === 'hooray' ||
reaction.content === 'rocket',
).length;
return upvotes >= upvoteCount;
}
28 changes: 14 additions & 14 deletions test/entrypoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ describe('Issue tests', {}, () => {
{ status: 200, body: [] },
)
.get(
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues?state=open&sort=updated&direction=asc&per_page=100',
{ status: 200, body: [] },
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues',
{ status: 200, body: [] }, { query: { state: 'open', sort: 'updated', direction: 'asc', per_page: '100' } }
)
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/263/timeline?per_page=100', {
status: 200,
Expand Down Expand Up @@ -306,8 +306,8 @@ describe('Issue tests', {}, () => {
{ status: 200, body: [] },
)
.get(
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues?state=open&sort=updated&direction=asc&per_page=100',
{ status: 200, body: [] },
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues',
{ status: 200, body: [] }, { query: { state: 'open', sort: 'updated', direction: 'asc', per_page: '100' } }
)
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/259/timeline?per_page=100', {
status: 200,
Expand Down Expand Up @@ -337,19 +337,18 @@ describe('Issue tests', {}, () => {
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues?state=open&per_page=100&sort=updated&direction=asc',
{ status: 200, body: [mockinputs.issue299] },
)
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/299/timeline?per_page=100', {
status: 200,
body: [],
})
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/299/timeline?per_page=100',
{ status: 200, body: [] },
)
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/299/reactions?per_page=100', {
status: 200,
body: [],
})
.post('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/260/comments', {
.post('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/299/comments', {
status: 200,
body: '',
})
.post('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/260/labels', {
.post('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/299/labels', {
status: 200,
body: '',
});
Expand Down Expand Up @@ -413,16 +412,16 @@ describe('Issue tests', {}, () => {
{ status: 200, body: [] },
)
.get(
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues?state=open&sort=updated&direction=asc&per_page=100',
{ status: 200, body: [mockinputs.issue242] },
'https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues',
{ status: 200, body: [mockinputs.issue242] }, { query: { state: 'open', sort: 'updated', direction: 'asc', per_page: '100' } }
)
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/242/timeline?per_page=100', {
status: 200,
body: [],
})
.get('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/242/reactions?per_page=100', {
status: 200,
body: [mockinputs.issue242Reactions],
body: mockinputs.issue242Reactions,
})
.post('https://api.github.com/repos/aws-actions/stale-issue-cleanup/issues/242/comments', {
status: 200,
Expand Down Expand Up @@ -479,7 +478,7 @@ describe('Configuration tests', {}, () => {
exemptPrLabels: process.env.EXEMPT_PR_LABELS,
responseRequestedLabel: process.env.RESPONSE_REQUESTED_LABEL,
minimumUpvotesToExempt: Number.parseInt(process.env.MINIMUM_UPVOTES_TO_EXEMPT ?? '0'),
cfsLabel: process.env.CFS_LABEL,
cfsLabel: process.env.CLOSED_FOR_STALENESS_LABEL,
issueTypes: process.env.ISSUE_TYPES?.split(','),
useCreatedDateForAncient: !!process.env.USE_CREATED_DATE_FOR_ANCIENT,
});
Expand Down Expand Up @@ -575,4 +574,5 @@ describe('Configuration tests', {}, () => {

expect(core.debug).toHaveBeenCalledWith('Issue is an issue, which are excluded');
});

});
2 changes: 1 addition & 1 deletion test/mockinputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export const actionInputs = {
STALE_PR_LABEL: 'stale-pr',
EXEMPT_PR_LABELS: 'go-away-bot',
RESPONSE_REQUESTED_LABEL: 'response-requested',
CFS_LABEL: 'closed-for-staleness',
CLOSED_FOR_STALENESS_LABEL: 'closed-for-staleness',
MINIMUM_UPVOTES_TO_EXEMPT: '1',
ISSUE_TYPES: 'issues,pull_requests',
};
Expand Down

0 comments on commit 941c747

Please sign in to comment.