Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE THIS PR] Add slash command "/black" to format PRs #645

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/black-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: black-command
on:
repository_dispatch:
types: [black-command]
jobs:
black:
runs-on: ubuntu-latest
steps:
# Checkout the pull request branch
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

# Setup Python environment
- uses: actions/setup-python@v1

# Install black
- name: Install black
run: pip install black

# Execute black in check mode
- name: Black
id: black
run: echo ::set-output name=format::$(black --check --quiet . || echo "true")

# Execute black and commit the change to the PR branch
- name: Commit to the PR branch
if: steps.black.outputs.format == 'true'
run: |
black .
git config --global user.name 'actions-bot'
git config --global user.email '58130806+actions-bot@users.noreply.github.com'
git commit -am "[black-command] fixes"
git push

- name: Add reaction
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.PAT }}
Copy link
Member

@weiji14 weiji14 Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whose Personal Access Token (PAT) is this, and what scope does it have? I see it's stored as a secret in the PyGMT repo (though I can't see the secret itself), and know that it's needed to let the Github Action 'bot' do the work. Just asking because I realize at conda-forge/gmt-feedstock#100 (comment) that we might need to use a PAT there too. Was wondering if we could have a GMT organization-wide secret PAT for these Github Actions that require permission to make commits.

Alternatively, we could look into using https://github.com/tibdex/github-app-token - i.e. make an organization GMT Github App, and use that App to generate what is basically a PAT token on the fly (rather than one of our personal ones). See also https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens for instructions on how to set this up. I'd help out with this but haven't got admin permissions in the GMT organization 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whose Personal Access Token (PAT) is this, and what scope does it have?

It's a PAT of my own account, with the repo scope.

Was wondering if we could have a GMT organization-wide secret PAT for these Github Actions that require permission to make commits.

It seems impossible to have an organization-wide PAT. The only way is someone generates a PAT and saves it as an organization-wide secret.

Alternatively, we could look into using https://github.com/tibdex/github-app-token - i.e. make an organization GMT Github App, and use that App to generate what is basically a PAT token on the fly (rather than one of our personal ones).

Yes, it looks promising.

I'd help out with this but haven't got admin permissions in the GMT organization.

Perhaps you can ask for admin permissions if necessary.


BTW, this PR doesn't work. The working one is PR #646.

Copy link
Member

@weiji14 weiji14 Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, shall we try using tibdex/github-app-token then? The step by step instructions at https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#authenticating-with-github-app-generated-tokens seem fairly straightforward. After we make the GMT-bot Github App, we can 'install' it here on GenericMappingTools/pygmt and at GenericMappingTools/gmt-feedstock to authenticate these bots.

And yes, I'll review things on #646 later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe hold on for a while, Github is experiencing some degraded performance (see https://www.githubstatus.com/incidents/28js6274ybpb. Noticed this in one of my other PRs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the github incident is resolved, right?

repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray
16 changes: 16 additions & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Slash Command Dispatch
on:
issue_comment:
# Type "edited" added here for test purposes. Where possible, avoid
# using to prevent processing unnecessary events.
types: [created, edited]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.PAT }}
commands: black
issue-type: pull-request