diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a46b7a0..b298223 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -56,6 +56,7 @@ jobs: with: stale-label: stale days-before-close: 7 + close-message: Closing this issue as it has become stale. dry-run: true - name: Check output diff --git a/action.yml b/action.yml index d4574a5..3f55395 100644 --- a/action.yml +++ b/action.yml @@ -13,19 +13,20 @@ inputs: default: ${{ github.token }} github-repo: required: true - description: GitHub `author/repository` for which stale issues are paused + description: GitHub `owner/repository` for which stale issues are paused default: ${{ github.repository }} stale-label: required: true description: Label which marks an issue as stale days-before-close: required: true - description: Days before an issue is closed after the stale label has been added it + description: Days before an issue is closed after the stale label has been added to it close-comment: + required: true description: Comment which will be added to issues when closing dry-run: description: Run the action without effectively closing stale issues - default: false + default: 'false' outputs: closed-issues: diff --git a/dist/index.js b/dist/index.js index 1916334..b2b3d7d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -95,7 +95,7 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``)}S.g } } } - `,{issue:n,cursor:c});if(E=l.nodes.find(({label:{name:C}})=>C===t),!l.pageInfo.hasPreviousPage)break;c=l.pageInfo.startCursor}while(!E);if(!E){xs.default.warning(`Couldn't get labeling date for issue #${a} (${g})`);continue}let Q=(0,qt.default)(E.createdAt);if(Q.isSameOrBefore(s)){let l=Q.from(s,!0);yield{number:a,url:g,staleSince:l}}else{let l=Q.to(s,!0);xs.default.info(`Issue #${a} (${g}) is not yet stale, will become stale in ${l}`)}}}var bc=Fe(_r(),1);async function Gh({octokit:A,ownerRepo:e,closeMessage:t,dryRun:r},{number:s,url:o,staleSince:n}){if(r){bc.default.info(`Issue #${s} (${o}) is stale since ${n} and would have been closed (dry-run)`);return}t&&await A.rest.issues.createComment({...e,issue_number:s,body:t}),await A.rest.issues.update({...e,issue_number:s,state:"closed",state_reason:"not_planned"}),bc.default.info(`Issue #${s} (${o}) is stale since ${n} and has been closed`)}var ff=Fe(df(),1),mt=Fe(_r(),1);async function pf(){let A=ff.default.getOctokit(mt.default.getInput("github-token")),[e,t]=mt.default.getInput("github-repo").split("/");if(!e||!t)throw new Error('"github-repo" must be provided in form of "/"');let r={owner:e,repo:t},s=mt.default.getBooleanInput("dry-run"),o=mt.default.getInput("stale-label");try{await A.request("GET /repos/{owner}/{repo}/labels/{name}",{...r,name:o,headers:{"X-GitHub-Api-Version":"2022-11-28"}})}catch{let a=`"stale-label" doesn't refer to an existing label or repository cannot be accessed`;if(s)mt.default.warning(a);else throw new Error(a)}let n=Number.parseInt(mt.default.getInput("days-before-close"));if(Number.isNaN(n))throw new TypeError('"days-before-close" must be a number');let i=mt.default.getInput("close-message")||null;return{octokit:A,ownerRepo:r,staleLabel:o,daysBeforeClose:n,closeMessage:i,dryRun:s}}try{let A=await pf(),e=Uh(A),t=[];for await(let r of e)await Gh(A,r),t.push(r.number);Wc.default.setOutput("closed-issues",t)}catch(A){let e=A instanceof Error?A.message:String(A);Wc.default.setFailed(e)} + `,{issue:n,cursor:c});if(E=l.nodes.find(({label:{name:C}})=>C===t),!l.pageInfo.hasPreviousPage)break;c=l.pageInfo.startCursor}while(!E);if(!E){xs.default.warning(`Couldn't get labeling date for issue #${a} (${g})`);continue}let Q=(0,qt.default)(E.createdAt);if(Q.isSameOrBefore(s)){let l=Q.from(s,!0);yield{number:a,url:g,staleSince:l}}else{let l=Q.to(s,!0);xs.default.info(`Issue #${a} (${g}) is not yet stale, will become stale in ${l}`)}}}var bc=Fe(_r(),1);async function Gh({dryRun:A,octokit:e,ownerRepo:t,closeMessage:r},{number:s,url:o,staleSince:n}){if(A){bc.default.info(`Issue #${s} (${o}) is stale since ${n} and would have been closed (dry-run)`);return}await e.rest.issues.createComment({...t,issue_number:s,body:r}),await e.rest.issues.update({...t,issue_number:s,state:"closed",state_reason:"not_planned"}),bc.default.info(`Issue #${s} (${o}) is stale since ${n} and has been closed`)}var ff=Fe(df(),1),mt=Fe(_r(),1);async function pf(){let A=ff.default.getOctokit(mt.default.getInput("github-token")),[e,t]=mt.default.getInput("github-repo").split("/");if(!e||!t)throw new Error('"github-repo" must be provided in form of "/"');let r={owner:e,repo:t},s=mt.default.getBooleanInput("dry-run"),o=mt.default.getInput("stale-label");try{await A.request("GET /repos/{owner}/{repo}/labels/{name}",{...r,name:o,headers:{"X-GitHub-Api-Version":"2022-11-28"}})}catch{let a=`"stale-label" doesn't refer to an existing label or repository cannot be accessed`;if(s)mt.default.warning(a);else throw new Error(a)}let n=Number.parseInt(mt.default.getInput("days-before-close"));if(Number.isNaN(n))throw new TypeError('"days-before-close" must be a number');let i=mt.default.getInput("close-message");return{octokit:A,ownerRepo:r,staleLabel:o,daysBeforeClose:n,closeMessage:i,dryRun:s}}try{let A=await pf(),e=Uh(A),t=[];for await(let r of e)await Gh(A,r),t.push(r.number);Wc.default.setOutput("closed-issues",t)}catch(A){let e=A instanceof Error?A.message:String(A);Wc.default.setFailed(e)} /*! Bundled license information: undici/lib/fetch/body.js: diff --git a/src/lib/close-issue.ts b/src/lib/close-issue.ts index ad3de06..bf67db9 100644 --- a/src/lib/close-issue.ts +++ b/src/lib/close-issue.ts @@ -3,19 +3,17 @@ import core from '@actions/core'; import type { Config } from './get-config.js'; import type { Issue } from './get-stale-issues.js'; -export async function closeIssue({ octokit, ownerRepo, closeMessage, dryRun }: Config, { number, url, staleSince }: Issue) { +export async function closeIssue({ dryRun, octokit, ownerRepo, closeMessage }: Config, { number, url, staleSince }: Issue) { if (dryRun) { core.info(`Issue #${number} (${url}) is stale since ${staleSince} and would have been closed (dry-run)`); return; } - if (closeMessage) { - await octokit.rest.issues.createComment({ - ...ownerRepo, - issue_number: number, - body: closeMessage, - }); - } + await octokit.rest.issues.createComment({ + ...ownerRepo, + issue_number: number, + body: closeMessage, + }); await octokit.rest.issues.update({ ...ownerRepo, diff --git a/src/lib/get-config.ts b/src/lib/get-config.ts index 083ef01..b46649e 100644 --- a/src/lib/get-config.ts +++ b/src/lib/get-config.ts @@ -7,7 +7,7 @@ export interface Config { ownerRepo: { owner: string; repo: string }; staleLabel: string; daysBeforeClose: number; - closeMessage: string | null; + closeMessage: string; dryRun: boolean; } @@ -52,7 +52,7 @@ export async function getConfig(): Promise { throw new TypeError('"days-before-close" must be a number'); } - const closeMessage = core.getInput('close-message') || null; + const closeMessage = core.getInput('close-message'); return { octokit,