From 5f66d8c220343b25c71abff9f1b989fca9a24f7d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 10 Mar 2025 09:49:35 +0100 Subject: [PATCH 1/3] Rename file blocked.yml to pull_request.yml --- .github/workflows/{blocked.yml => pull_request.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{blocked.yml => pull_request.yml} (100%) diff --git a/.github/workflows/blocked.yml b/.github/workflows/pull_request.yml similarity index 100% rename from .github/workflows/blocked.yml rename to .github/workflows/pull_request.yml From afc46676a0177ddc916e6d9ae1d6acd478ddd221 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 10 Mar 2025 09:53:16 +0100 Subject: [PATCH 2/3] Automatically add label 'Z-Community-PR' to community PRs. --- .github/workflows/pull_request.yml | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index d6e592cb0d..dde2a75a6e 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,7 +1,7 @@ -name: Prevent blocked +name: Pull Request on: pull_request: - types: [opened, labeled, unlabeled] + types: [ opened, labeled, unlabeled ] jobs: prevent-blocked: name: Prevent blocked @@ -15,3 +15,31 @@ jobs: with: script: | core.setFailed("PR has been labeled with X-Blocked; it cannot be merged."); + + community-prs: + name: Label Community PRs + runs-on: ubuntu-latest + if: github.event.action == 'opened' + permissions: + pull-requests: write + steps: + - name: Check membership + if: github.event.pull_request.user.login != 'renovate[bot]' + uses: tspascoal/get-user-teams-membership@57e9f42acd78f4d0f496b3be4368fc5f62696662 # v3 + id: teams + with: + username: ${{ github.event.pull_request.user.login }} + organization: element-hq + team: Core Team + GITHUB_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} + - name: Add label + if: steps.teams.outputs.isTeamMember == 'false' + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['Z-Community-PR'] + }); From 40990abf0b59523374ef308c9bef912dc4e31745 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 10 Mar 2025 09:56:37 +0100 Subject: [PATCH 3/3] Forbid develop branch fork contributions --- .github/workflows/pull_request.yml | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index dde2a75a6e..42537c54b4 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,7 +1,12 @@ name: Pull Request on: pull_request: - types: [ opened, labeled, unlabeled ] + types: [ opened, edited, labeled, unlabeled, synchronize ] + workflow_call: + secrets: + ELEMENT_BOT_TOKEN: + required: true + jobs: prevent-blocked: name: Prevent blocked @@ -43,3 +48,30 @@ jobs: repo: context.repo.repo, labels: ['Z-Community-PR'] }); + + close-if-fork-develop: + name: Forbid develop branch fork contributions + runs-on: ubuntu-latest + if: > + github.event.action == 'opened' && + github.event.pull_request.head.ref == 'develop' && + github.event.pull_request.head.repo.full_name != github.repository + steps: + - name: Close pull request + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Thanks for opening this pull request, unfortunately we do not accept contributions from the main" + + " branch of your fork, please re-open once you switch to an alternative branch for everyone's sanity.", + }); + + github.rest.pulls.update({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + state: 'closed' + });