Skip to content

Commit

Permalink
Merge pull request #1013 from rohit-gohri/fix-github-action-condition
Browse files Browse the repository at this point in the history
Fix GitHub Actions condition
  • Loading branch information
orta committed Mar 13, 2020
2 parents 04c3345 + b7e1091 commit 0ca95c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ x

<!-- Your comment below this -->

- Don't use hardcoded userId to update comments if using personal token in Github Actions - [@rohit-gohri]
- Add the staged flag to `danger local` command - [@soyn]
- Disable warning in Github Action if using DANGER_GITHUB_API_TOKEN- [@rohit-gohri]
- Disable warning in Github Action if using DANGER_GITHUB_API_TOKEN - [@rohit-gohri]
- Update `parse-diff` library - [@417-72KI]
- Fix repository slug in Jenkins provider - [sandratatarevicova]
- Fix Typos across danger-js Repo - [@yohix]
Expand Down
17 changes: 16 additions & 1 deletion source/ci_source/providers/GitHubActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,22 @@ import { readFileSync, existsSync } from "fs"
* env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
* ```
*
* [GitHub automatically creates a `GITHUB_TOKEN` secret to use in your workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token). You can use the `GITHUB_TOKEN` to authenticate in a workflow run.
* [GitHub automatically creates a `GITHUB_TOKEN` secret to use in your workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token).
* You can use the `GITHUB_TOKEN` to authenticate in a workflow run.
* Using this token will post the danger comment as the `github-actions` app user.
*
* #### Using Personal Tokens
*
* If you need to post the danger comment as some particular user or for some other reason
* you need to use a personal token for danger then you can provide it in env as DANGER_GITHUB_API_TOKEN,
* but make sure that this is not the [automatically generated GITHUB_TOKEN in actions](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)
* otherwise comments will not be updated and new ones will be created everytime.
*
* ```yml
* - name: Danger JS
* uses: danger/danger-js@9.1.6
* env: DANGER_GITHUB_API_TOKEN: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
* ```
*
*/

Expand Down
5 changes: 4 additions & 1 deletion source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ export class GitHubAPI {
return parseInt(perilID)
}

const useGitHubActionsID = process.env["GITHUB_WORKFLOW"]
const useGitHubActionsID = process.env["GITHUB_WORKFLOW"] && !process.env["DANGER_GITHUB_API_TOKEN"]
if (useGitHubActionsID) {
// This is the user.id of the github-actions app(https://github.com/apps/github-actions)
// that is used to comment when using danger in Github Action
// with GITHUB_TOKEN (https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token)
return 41898282
}

Expand Down

0 comments on commit 0ca95c5

Please sign in to comment.