-
-
Notifications
You must be signed in to change notification settings - Fork 11
70 lines (65 loc) · 4.05 KB
/
community-contributions.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
name: Community Contributions
on:
workflow_call:
inputs:
forum_category:
description: "The forum category used in the 'open a new topic' link"
required: true
type: string
secrets:
github_membership_token:
description: "The github token used to check org membership with"
required: false
permissions:
issues: write
pull-requests: write
jobs:
pause:
name: Pause Community Contributions
runs-on: ubuntu-22.04
steps:
- name: Detect if user is org member
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
id: is-organization-member
with:
github-token: ${{ secrets.github_membership_token || secrets.GITHUB_TOKEN }}
script: |
if (context.actor == 'dependabot[bot]' || context.actor == 'exercism-bot' || context.actor == 'github-actions[bot]') {
return true;
}
return github.rest.orgs.checkMembershipForUser({
org: context.repo.owner,
username: context.actor,
}).then(response => response.status == 204)
.catch(err => false);
- name: Comment
if: steps.is-organization-member.outputs.result == 'false'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const isIssue = !!context.payload.issue;
const subject = context.payload.issue || context.payload.pull_request;
const thing = (isIssue ? 'issue' : 'PR');
const aThing = (isIssue ? 'an issue' : 'a PR');
const forumCategory = '${{ inputs.forum_category }}'
const link = `https://forum.exercism.org/new-topic?title=${encodeURI(subject.title)}&body=${encodeURI(subject.body)}&category=${encodeURI(forumCategory)}`
const body = isIssue
? `Hello. Thanks for opening an issue on Exercism 🙂\n\nAt Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.\n\nThis issue will be automatically closed. Please use [this link](${link} ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!\n\nIf you're interested in learning more about this auto-responder, please read [this blog post](https://exercism.org/blog/contribution-guidelines-nov-2023).`
: `Hello. Thanks for opening a PR on Exercism 🙂\n\nWe ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.\n\nYou can use [this link](${link} ) to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.\n\nIf you're interested in learning more about this auto-responder, please read [this blog post](https://exercism.org/blog/contribution-guidelines-nov-2023).\n\n---\n\n_Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it._`
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
- name: Close
if: steps.is-organization-member.outputs.result == 'false'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed',
})