Skip to content
Merged
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
115 changes: 94 additions & 21 deletions .github/workflows/community_contribution.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: "Community contribution"
on:
pull_request_target:
types: [opened, reopened]
types: [opened, reopened, edited]

jobs:
community-pr-message:
if: ${{ github.event.action != 'edited' || (github.event.pull_request.state == 'closed' && !github.event.pull_request.merged) }}
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
concurrency:
group: community-contribution-${{ github.event.pull_request.number }}
cancel-in-progress: false
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
queue: max
Comment thread
weronikaolejniczak marked this conversation as resolved.
Resolved
env:
USER_LOGIN: ${{ github.event.pull_request.user.login }}
PR_NUMBER: ${{ github.event.pull_request.number }}
Expand Down Expand Up @@ -53,43 +58,111 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_BODY: ${{ github.event.pull_request.body }}
ACTION: ${{ github.event.action }}
SENDER_LOGIN: ${{ github.event.sender.login }}
USER_TYPE: ${{ github.event.pull_request.user.type }}
run: |
set -euo pipefail

gh pr comment "$PR_NUMBER" --body "👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?"
gh pr edit "$PR_NUMBER" --add-label "community contribution"

guidelines='https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/README.md'
help_wanted='https://github.com/elastic/eui/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22'
new_issue='https://github.com/elastic/eui/issues/new/choose'
marker='<!-- community-contribution-autoclose -->'

# Authors without write access can't reopen a pull request the bot closed, so the bot reopens it after an edit
if [[ "$ACTION" == edited ]]; then
# A queued run can start after an earlier one already reopened the pull request
closed_by=$(gh api "repos/$GH_REPO/issues/$PR_NUMBER" --jq 'if .state == "closed" then .closed_by.login // "" else "" end')
# The stale workflow also closes as github-actions[bot], so the bot's latest comment must be this workflow's
auto_closed=$(gh api --paginate "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
--jq '.[] | select(.user.login == "github-actions[bot]") | .body | contains("<!-- community-contribution-autoclose -->")' \
| tail -n 1)
if [[ "$closed_by" != "github-actions[bot]" || "$auto_closed" != true ]]; then
echo "Not closed by this workflow; nothing to do."
exit 0
fi
fi

# The event payload can be older than an edit made while this run was queued
pr_body=$(gh api "repos/$GH_REPO/pulls/$PR_NUMBER" --jq '.body // ""')
# GitHub ignores closing keywords in HTML comments, like the PR template's example
pr_body=$(printf '%s' "$pr_body" | perl -0pe 's/<!--.*?-->//gs')
Comment thread
weronikaolejniczak marked this conversation as resolved.
Resolved

issue_numbers=$(
printf '%s\n' "$PR_BODY" \
| grep -oiE '(close[sd]?|fix(e[sd])?|resolve[sd]?)[[:space:]]+(https://github\.com/elastic/eui/issues/|#|elastic/eui#)[0-9]+' \
printf '%s\n' "$pr_body" \
| grep -oiE '\b(close[sd]?|fix(e[sd])?|resolve[sd]?):?[[:space:]]+(https://github\.com/elastic/eui/issues/|#|elastic/eui#)[0-9]+' \
| grep -oE '[0-9]+$' \
| sort -u \
|| true
)

if [[ -z "$issue_numbers" ]]; then
gh pr comment "$PR_NUMBER" --body "We don't accept community contributions without a linked issue labelled \"help wanted\". Please file or link one first. See our [contribution guidelines]($guidelines)."
exit 0
fi

has_help_wanted=false
inspected=0
failed=0
for issue_number in $issue_numbers; do
is_help_wanted=$(gh issue view "$issue_number" --json labels --jq 'any(.labels[]; .name == "help wanted")' 2>/dev/null) || continue
inspected=$((inspected + 1))
if [[ "$is_help_wanted" == true ]]; then
has_help_wanted=true
break
# The issues endpoint also returns pull requests
if result=$(gh api "repos/$GH_REPO/issues/$issue_number" \
--jq '.pull_request == null and .state == "open" and any(.labels[]; .name == "help wanted")' 2>&1); then
if [[ "$result" == true ]]; then
has_help_wanted=true
break
fi
else
case "$result" in
*"HTTP 404"* | *"HTTP 410"*) ;;
*) failed=$((failed + 1)) ;;
esac
fi
done

if [[ "$inspected" -eq 0 ]]; then
echo "::warning::Could not read linked issues; skipping help wanted comment."
if [[ "$has_help_wanted" != true && "$failed" -gt 0 ]]; then
if [[ "$ACTION" == edited ]]; then
echo "::warning::Could not read linked issues; leaving the pull request closed."
exit 0
fi
echo "::warning::Could not read linked issues; leaving the pull request open."
has_help_wanted=true
fi

# Only the author or someone with write access can reopen, so a reopen by anyone else is a maintainer override.
# Bot pull requests don't link issues, so they're never closed.
if [[ "$USER_TYPE" == Bot || ( "$ACTION" == reopened && "$SENDER_LOGIN" != "$USER_LOGIN" ) ]]; then
Comment thread
weronikaolejniczak marked this conversation as resolved.
Resolved
has_help_wanted=true
fi

if [[ "$has_help_wanted" != true && "$ACTION" == edited ]]; then
echo "Still no open help wanted issue; leaving the pull request closed."
exit 0
fi

if [[ "$has_help_wanted" != true ]]; then
gh pr comment "$PR_NUMBER" --body "We don't accept community contributions for issues not labelled \"help wanted\". Please read our [contribution guidelines]($guidelines)."
if [[ -z "$issue_numbers" ]]; then
reason="This pull request isn't linked to an issue."
else
reason="None of the issues this pull request closes is open and labelled \`help wanted\`."
fi

body=$(cat <<EOF
$marker
👋 Thanks for your interest in contributing to EUI! We only accept community pull requests for open issues labelled [\`help wanted\`]($help_wanted), so we're closing this one. $reason

To get it reviewed:

1. Find an open issue labelled \`help wanted\`. If the issue you're working on doesn't have that label, comment on it with your proposed solution. We'll add the label if we agree.
2. Edit this pull request's description to link that issue with a closing keyword, e.g. \`Fixes #123\`, \`Closes #123\` or \`Resolves #123\`. Mentions like "related to #123", closed issues and pull requests don't count.

We'll reopen this pull request automatically once its description links an open \`help wanted\` issue. If the label is added after your last edit, edit the description again to rerun the check.

If you need a capability that doesn't have an issue yet, [open one]($new_issue) and wait for us to discuss it before writing code. Opening an issue isn't enough on its own: we add \`help wanted\` only once we've agreed on the change and want it contributed. See our [contribution guidelines]($guidelines) for details.
EOF
)

gh pr close "$PR_NUMBER" --comment "$body"
Comment thread
weronikaolejniczak marked this conversation as resolved.
Resolved
exit 0
fi

if [[ "$ACTION" == edited ]]; then
gh pr reopen "$PR_NUMBER"
fi

gh pr comment "$PR_NUMBER" --body "👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?"
gh pr edit "$PR_NUMBER" --add-label "community contribution"
4 changes: 2 additions & 2 deletions .github/workflows/stale_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
steps:
- uses: actions/stale@v10
with:
stale-issue-message: '👋 Hi there - this issue hasn''t had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it''s unlikely that we''ll pick this issue up. We would sincerely appreciate a PR/community contribution if this is something that matters to you! If not, and there is no further activity on this issue for another 6 months (i.e. it''s stale for over a year), the issue will be auto-closed.'
close-issue-message: '❌ Per our previous message, this issue is auto-closing after having been open and inactive for a year. If you strongly feel this is still a high-priority issue, or are interested in contributing, please leave a comment or open a new issue linking to this one for context.'
stale-issue-message: '👋 Hi there - this issue hasn''t had any activity in 6 months. If the EUI team has not explicitly expressed that this is something on our roadmap, it''s unlikely that we''ll pick this issue up. If it matters to you, leave a comment with your use case. If you''d like to contribute and this issue isn''t labelled `help wanted`, comment with a proposed solution and wait for us to add the label before opening a pull request; we close community pull requests for issues without it. See our [contribution guidelines](https://github.com/elastic/eui/blob/main/wiki/contributing-to-eui/README.md). If there''s no further activity on this issue for another 6 months (i.e. it''s stale for over a year), the issue will be auto-closed.'
close-issue-message: '❌ Per our previous message, this issue is auto-closing after having been open and inactive for a year. If you strongly feel this is still a high-priority issue, please leave a comment or open a new issue linking to this one for context. If you''d like to contribute, comment with a proposed solution and wait for us to reopen it with the `help wanted` label before opening a pull request.'
days-before-issue-stale: 180
days-before-close: 180
stale-issue-label: 'stale-issue'
Expand Down
4 changes: 4 additions & 0 deletions wiki/contributing-to-eui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ If you are having a problem with EUI, [file an issue](https://github.com/elastic

If you want to contribute a fix for an issue that affects you, comment on that issue with a proposed solution. We can discuss it there. If we agree, we will add the `help wanted` label.

Opening an issue doesn't open it for contribution. Wait for the `help wanted` label before you start on a PR; PRs for issues without it are closed automatically.

## What not to contribute

Unless agreed upon previously:
Expand All @@ -31,6 +33,8 @@ Unless agreed upon previously:

We do not assign issues to community members. Comment on the `help wanted` issue before you start so others know you are working on it.

Link the issue in your PR description with a closing keyword, e.g. `Fixes #123`, `Closes #123` or `Resolves #123`. We automatically close community PRs that don't close an open `help wanted` issue. Mentions like "related to #123", closed issues and other PRs don't count. Edit the description of the closed PR to add the link, and we'll reopen it automatically.

## Typical change flow

A typical contribution moves through these steps:
Expand Down