Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

feat: Add action workflow for blocking merge via labels #191

Merged
merged 1 commit into from
Sep 22, 2021

Conversation

averikitsch
Copy link
Contributor

Addresses #138

On each label/un-label event on a pull request will execute the workflow. The settings need to be updated to have this required status check.

Limitations of GitHub Actions:

  • Each label add or removal, even if done as a batch, triggers a check in the checks tab though it should only show up once in the PR status checks.

Decisions made:

  • This uses action actions/github-script@v4 to extract the event and PR context for more control and results in only 1 status check. This is compared to Adam's example using workflow expressions and functions to extract this information. There was minimal control over arrays of labels.

Future considerations:

  • This similar pattern using actions/github-script@v4 can be used to add labels on PR creation
     - uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            github.issues.addLabels({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              labels: ['do not merge']
            })
  • Similar add comments to the PR
github.issues.createComment({
  issue_number: context.issue.number,
  owner: context.repo.owner,
  repo: context.repo.repo,
  body: welcomeMessage
});
  • Lastly, can read the PR body
      - uses: actions/github-script@v4
        with:
          script: |
            const body = context.payload.pull_request.body;
            if (body.includes("Decision Record")) {
         ...

@averikitsch averikitsch requested a review from a team as a code owner September 22, 2021 21:35
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 22, 2021
Copy link
Collaborator

@grayside grayside left a comment

Choose a reason for hiding this comment

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

Neat! I assume "core" is a basic Github Actions built-in I somehow hadn't understood yet.

@averikitsch
Copy link
Contributor Author

Neat! I assume "core" is a basic Github Actions built-in I somehow hadn't understood yet.

The action exposes Github libraries and context available for building actions. The core library provides functions for setting results, logging, registering secrets and exporting variables across actions. Your example works, just not as flexible.

@averikitsch averikitsch merged commit c7cdc95 into main Sep 22, 2021
@grayside
Copy link
Collaborator

Thanks for making it work & look good.

@grayside grayside added the persona: maintainer [meta] Related to project maintenance. label Sep 28, 2021
@grayside grayside added this to the v0.5.0 milestone Sep 28, 2021
@pattishin pattishin deleted the block-merge branch January 6, 2023 16:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement. persona: maintainer [meta] Related to project maintenance.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants