Skip to content

Commit

Permalink
Merge pull request #635 from EnviousSwan/cancel-token-refresh-at-the-end
Browse files Browse the repository at this point in the history
Cancel GitHub token refresh at the end
  • Loading branch information
alejandrohdezma committed Sep 9, 2024
2 parents 74a9a67 + ba67ff8 commit 7292c0b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/action/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ async function run(): Promise<void> {
], inputs.steward.extraJars)
} finally {
await workspace.saveWorkspaceCache()
await workspace.cancelTokenRefresh()
}

if (files.existsSync(workspace.runSummary_md)) {
Expand Down
13 changes: 12 additions & 1 deletion src/modules/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class Workspace {
readonly askpass_sh: NonEmptyString
readonly runSummary_md: string

private intervalId: NodeJS.Timeout | undefined

constructor(
private readonly logger: Logger,
private readonly files: Files,
Expand Down Expand Up @@ -123,7 +125,7 @@ export class Workspace {
}

await this.writeAskPass(token)
setInterval(async () => {
this.intervalId = setInterval(async () => {
await this.writeAskPass(token)
this.logger.info('✓ GitHub Token refreshed')
}, 1000 * 60 * 50)
Expand Down Expand Up @@ -154,6 +156,15 @@ export class Workspace {
this.files.writeFileSync(this.askpass_sh.value, `#!/bin/sh\n\necho '${token}'`)
}

/**
* Cancels the token refresh if it is currently scheduled.
*/
async cancelTokenRefresh(): Promise<void> {
if (this.intervalId) {
clearInterval(this.intervalId)
}
}

/**
* Gets the first eight characters of the SHA-256 hash value for the
* provided file's contents.
Expand Down

0 comments on commit 7292c0b

Please sign in to comment.