Revision control

Copy as Markdown

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: 'Contribution Guardrails'
on:
pull_request_target:
types: [labeled, unlabeled, reopened]
permissions: {}
jobs:
contribution-check:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
concurrency:
group: contribution-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.pull_request.number }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
steps:
- name: Handle does-not-meet-guidelines label
if: github.event.action == 'labeled' && github.event.label.name == 'does-not-meet-guidelines'
shell: bash
env:
# __AUTHOR__ is substituted at runtime rather than interpolated by the workflow
# templater, so event data never becomes part of the script itself.
BODY: |
:wave: Thanks @__AUTHOR__ for your contribution.
This pull request is being closed because it does not meet the project's
[contribution guidelines](https://github.com/mozilla-mobile/firefox-ios/blob/main/CONTRIBUTING.md).
Common reasons might include:
- The changes are too large or not scoped to a single issue
- The PR lacks sufficient context or explanation
- The implementation does not follow existing patterns or project conventions
- The work was not validated (build, tests, or clear verification steps)
- The contribution was not aligned with maintainers before starting
To respect reviewer time and maintain code quality, we only review pull requests
that meet the baseline described in the contribution guidelines.
If you would like to continue working on this, please:
- Review the contribution guidelines linked above
- Ensure your work is for an issue labelled `contributor-friendly` or you have received explicit approval to work on an issue from a maintainer
- Break the work into smaller, focused pull requests (generally under ~400 lines)
Once the work is ready and aligned, feel free to open a new pull request.
If you have questions or would like to discuss on an approach, you can reach out on
[Element](https://chat.mozilla.org/#/room/#fx-ios:mozilla.org) or comment on the related issue.
Thank you for your understanding.
run: |
# No `set -e`: these actions are best-effort. Failures are surfaced as warnings
# rather than failing the run, because "already closed" and "label not present"
# are expected outcomes, not errors.
set -uo pipefail
try() {
local desc="$1"; shift
local n=0
until "$@"; do
n=$((n + 1))
if [ "$n" -ge 3 ]; then
echo "::warning::${desc} did not succeed after ${n} attempts"
return 0
fi
sleep 2
done
}
body=${BODY//__AUTHOR__/$PR_AUTHOR}
try "commenting on PR #$NUMBER" gh pr comment "$NUMBER" -R "$GH_REPO" -b "$body"
try "closing PR #$NUMBER" gh pr close "$NUMBER" -R "$GH_REPO"
- name: Handle outside-approved-scope label
if: github.event.action == 'labeled' && github.event.label.name == 'outside-approved-scope'
shell: bash
env:
BODY: |
:wave: Thanks @__AUTHOR__ for your contribution.
This pull request is being closed because it introduces changes that were
not previously aligned with the maintainers. Please have a look at our contribution guidelines
[here](https://github.com/mozilla-mobile/firefox-ios/blob/main/CONTRIBUTING.md#guidelines-for-contributing).
If you’d like to work on something that isn’t marked as contributor-friendly,
please reach out to a team member first to confirm whether it’s available.
Work that isn’t pre-aligned can be declined, as features and priorities are
carefully planned with product and design, and can also conflict with
work that is already in progress.
We absolutely welcome ideas and contributions. If you’d like to move this
forward, please let's align first. This can be done on [Element](https://chat.mozilla.org/#/room/#fx-ios:mozilla.org),
or the ticket itself for this feature. Thank you!
run: |
set -uo pipefail
try() {
local desc="$1"; shift
local n=0
until "$@"; do
n=$((n + 1))
if [ "$n" -ge 3 ]; then
echo "::warning::${desc} did not succeed after ${n} attempts"
return 0
fi
sleep 2
done
}
body=${BODY//__AUTHOR__/$PR_AUTHOR}
try "commenting on PR #$NUMBER" gh pr comment "$NUMBER" -R "$GH_REPO" -b "$body"
try "closing PR #$NUMBER" gh pr close "$NUMBER" -R "$GH_REPO"
- name: Reopen PR when label removed
if: github.event.action == 'unlabeled' && (github.event.label.name == 'does-not-meet-guidelines' || github.event.label.name == 'outside-approved-scope')
shell: bash
run: |
set -uo pipefail
try() {
local desc="$1"; shift
local n=0
until "$@"; do
n=$((n + 1))
if [ "$n" -ge 3 ]; then
echo "::warning::${desc} did not succeed after ${n} attempts"
return 0
fi
sleep 2
done
}
# Already-open PRs are a normal case here, so a failure is informational only.
try "reopening PR #$NUMBER" gh pr reopen "$NUMBER" -R "$GH_REPO"
- name: Cleanup labels on manual reopen
if: github.event.action == 'reopened'
shell: bash
run: |
set -uo pipefail
# Most reopened PRs never carried these labels, so removal failing is expected
# and deliberately not reported.
for label in does-not-meet-guidelines outside-approved-scope; do
gh pr edit "$NUMBER" -R "$GH_REPO" --remove-label "$label" || true
done