Skip to content

Commit 7c99145

Browse files
sparlantstoe
andauthored
Add the action name/path to the output (#111)
Co-authored-by: Stefan Stölzle <stoe@github.com>
1 parent c94a29a commit 7c99145

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

action.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {context} from '@actions/github'
99
const searchToken = getInput('search_token', {required: true})
1010
const token = getInput('token', {required: true})
1111
const allowList = getInput('allow_list_path')
12+
const reportType = getInput('report_type', {required: true})
1213
const workspace = process.env.GITHUB_WORKSPACE
1314

1415
const allowListPath = join(workspace, allowList)
@@ -18,7 +19,7 @@ import {context} from '@actions/github'
1819
throw new Error(`${allowList} is not an allowed path`)
1920
}
2021

21-
const ad = new ActionDetails({token, searchToken, allowList, context})
22+
const ad = new ActionDetails({token, searchToken, allowList, reportType, context})
2223

2324
await ad.getDetails()
2425
// await ad.postComment()

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ inputs:
99
description: 'GITHUB_TOKEN'
1010
required: true
1111
default: ${{ github.token }}
12+
report_type:
13+
description: 'comment, output, both'
14+
required: true
15+
default: 'comment'
1216
allow_list_path:
1317
description: 'Path to the GitHub Actions allow list YML within the repository'
1418
default: 'github-actions-allow-list.yml'
1519
outputs:
20+
actionName:
21+
description: 'Action name/path'
1622
isGitHubVerified:
1723
description: 'Is the GitHub Actions organization verified'
1824
isSecurityPolicyEnabled:

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/details.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ class ActionDetails {
6060
* @param {string} options.token GitHub Token
6161
* @param {string} options.searchToken GitHub Personal Access Token (PAT)
6262
* @param {string} options.allowList Path to the GitHub Actions allow list YML within the repository
63+
* @param {string} options.reportType Type of report to produce: comment, output, both
6364
* @param {import('@actions/github').context} options.context
6465
*/
65-
constructor({token, searchToken, allowList, context}) {
66+
constructor({token, searchToken, allowList, reportType, context}) {
6667
if (!token) {
6768
throw new Error('`token` is required')
6869
}
@@ -74,6 +75,7 @@ class ActionDetails {
7475
this.search = getOctokit(searchToken)
7576

7677
this.allowList = allowList
78+
this.reportType = reportType
7779
this.context = context
7880
}
7981

@@ -238,9 +240,14 @@ Please make sure this is intended by providing a business reason via comment bel
238240
contributors: contributors.length,
239241
}
240242

241-
this.addOutputs(details)
242-
const md = this.getMarkdown(details)
243-
this.postReviewComment(md, position)
243+
if (this.reportType === 'both' || this.reportType === 'output') {
244+
this.addOutputs(details)
245+
}
246+
247+
if (this.reportType === 'both' || this.reportType === 'comment') {
248+
const md = this.getMarkdown(details)
249+
this.postReviewComment(md, position)
250+
}
244251
} catch (error) {
245252
this.postReviewComment(
246253
`## :stop_sign: \`${owner}/${repo}\` is not a known GitHub Action
@@ -261,6 +268,7 @@ Please delete \`${owner}/${repo}\` from \`${this.allowList}\`!`,
261268
*/
262269
addOutputs(details) {
263270
const {
271+
action,
264272
actionRequestedVersion,
265273
url,
266274
description,
@@ -277,6 +285,8 @@ Please delete \`${owner}/${repo}\` from \`${this.allowList}\`!`,
277285
watchers,
278286
} = details
279287

288+
setOutput('actionName', action)
289+
280290
const isGitHubVerified = owner.type === 'Organization' && owner.isVerified === true
281291
setOutput('isGitHubVerified', isGitHubVerified)
282292

0 commit comments

Comments
 (0)