-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from crs-k/comment-update-flag
added input for enabling comments on issue updates
- Loading branch information
Showing
7 changed files
with
67 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import * as assert from 'assert' | ||
import * as core from '@actions/core' | ||
import {daysBeforeDelete, github, owner, repo} from './get-context' | ||
import {commentUpdates, daysBeforeDelete, github, owner, repo} from './get-context' | ||
|
||
export async function updateIssue( | ||
issueNumber: number, | ||
branch: string, | ||
commitAge: number | ||
): Promise<string> { | ||
let createdAt: string | ||
let createdAt = '' | ||
let commentUrl: string | ||
const daysUntilDelete = Math.abs(commitAge - daysBeforeDelete) | ||
try { | ||
const issueResponse = await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: `${branch} has had no activity for ${commitAge.toString()} days. \r \r This branch will be automatically deleted in ${daysUntilDelete.toString()} days. \r \r This issue was last updated on ${new Date().toString()}`, | ||
labels: [ | ||
{ | ||
name: 'stale branch 🗑️', | ||
color: 'B60205', | ||
description: 'Used by Stale Branches Action to label issues' | ||
} | ||
] | ||
}) | ||
|
||
createdAt = issueResponse.data.created_at || '' | ||
commentUrl = issueResponse.data.html_url || '' | ||
assert.ok(createdAt, 'Created At cannot be empty') | ||
core.info(`Issue #${issueNumber}: comment was created at ${createdAt}. ${commentUrl}`) | ||
} catch (err) { | ||
if (err instanceof Error) | ||
core.info( | ||
`No existing issue returned for issue number: ${issueNumber}. Description: ${err.message}` | ||
) | ||
createdAt = '' | ||
} | ||
if (commentUpdates === true) { | ||
try { | ||
const issueResponse = await github.rest.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: `${branch} has had no activity for ${commitAge.toString()} days. \r \r This branch will be automatically deleted in ${daysUntilDelete.toString()} days. \r \r This issue was last updated on ${new Date().toString()}`, | ||
labels: [ | ||
{ | ||
name: 'stale branch 🗑️', | ||
color: 'B60205', | ||
description: 'Used by Stale Branches Action to label issues' | ||
} | ||
] | ||
}) | ||
|
||
createdAt = issueResponse.data.created_at || '' | ||
commentUrl = issueResponse.data.html_url || '' | ||
assert.ok(createdAt, 'Created At cannot be empty') | ||
core.info(`Issue #${issueNumber}: comment was created at ${createdAt}. ${commentUrl}`) | ||
} catch (err) { | ||
if (err instanceof Error) | ||
core.info( | ||
`No existing issue returned for issue number: ${issueNumber}. Description: ${err.message}` | ||
) | ||
createdAt = '' | ||
} | ||
} | ||
return createdAt | ||
} |