-
Notifications
You must be signed in to change notification settings - Fork 98
92 lines (75 loc) · 4.24 KB
/
community-id-requester.yaml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: SAP Community profile URL requester
# What the execution context is:
# The assignment of a label to an issue or pull request indicating
# that the contribution was valuable.
# What it does:
# Adds a comment to the issue or pull request asking the author for
# their SAP Community ID.
# Why we need it:
# So that we can properly recognize the contribution in SAP Community.
# What's important to know:
# The label is specified at the start of the 'community-id-requester'
# job as an environment variable LABEL, and also in the job-level condition.
# Also, it adds a comment only after the first time the label is added, and
# only if there are no other issues / pull requests already labeled.
on:
pull_request_target:
types: [labeled]
issues:
types: [labeled]
jobs:
community-id-requester:
env:
LABEL: "contribution"
runs-on: ubuntu-20.04
if: contains(github.repositoryUrl, 'github.com') && github.event.label.name == 'contribution'
steps:
- id: token_gen
name: Generate app installation token
uses: machine-learning-apps/actions-app-token@0.21
with:
APP_PEM: ${{ secrets.SAP_CODOC_APP_PEM_BASE64 }}
APP_ID: ${{ secrets.SAP_CODOC_APP_ID }}
- id: checkout
name: Check out the repo
uses: actions/checkout@v3
with:
token: ${{ steps.token_gen.outputs.app_token }}
- id: issue_details
name: Determine related details if issue
if: github.event_name == 'issues'
run: |
echo "OBJECTTYPE=issue" >> $GITHUB_ENV
echo "CONTRIBUTIONTYPE=feedback" >> $GITHUB_ENV
echo "OBJECTNR=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "CONTRIBUTOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV
- id: pull_request_details
name: Determine related details if pull request
if: github.event_name == 'pull_request_target'
run: |
echo "OBJECTTYPE=pr" >> $GITHUB_ENV
echo "CONTRIBUTIONTYPE=content" >> $GITHUB_ENV
echo "OBJECTNR=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "CONTRIBUTOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV
- id: auth_gh
name: Authenticate gh to repo
run: echo -n ${{ steps.token_gen.outputs.app_token }} | gh auth login --with-token
- id: count_label_additions
name: Count number of times label has been added
run: |
endpoint="repos/${{ github.repository }}/issues/$OBJECTNR/events"
count=$(gh api --jq "[.[]|(select(.event==\"labeled\" and .label.name==\"$LABEL\"))] | length" $endpoint)
echo "LABELADDITIONCOUNT=$count" >> $GITHUB_ENV
- id: count_previous_labeled_objects
name: Count how many other issues / pull requests are so labeled
run: |
querystring="is:${OBJECTTYPE}+label:${LABEL}+author:${CONTRIBUTOR}+repo:${GITHUB_REPOSITORY}"
result=$(gh api --jq '.items[] | [.number, .title] | @tsv' "/search/issues?q=$querystring")
echo "$result"
echo "OBJECTCOUNT=$(wc -l <<< $result)" | tee -a $GITHUB_ENV
- id: requester
name: Ask for SAP Community profile URL if label added for first time and no prev labeled issue / pr
if: env.LABELADDITIONCOUNT == 1 && env.OBJECTCOUNT <= 1
run: |
printf "Thank you for your valuable ${CONTRIBUTIONTYPE} contribution, @${CONTRIBUTOR}! So that we can [recognize your contribution in the SAP Community](https://github.com/SAP-docs/contribution-guidelines/blob/main/docs/recognition.md), please check your SAP Community user ID (this is a number) in your [personal settings page](https://community.sap.com/t5/user/myprofilepage/tab/personal-profile) and share it with us in a reply to this comment. Make sure you just include the number in the reply.\n\nYour user ID is displayed as follows:\n\n**Change display name for User ID N**\n\nwhere N is your user ID. For example, [53 is the user ID of the user 'qmacro'](https://community.sap.com/t5/user/viewprofilepage/user-id/53).\n\nPlease note that we are currently refactoring our profile and badge system on the SAP Community, and will start assigning badges again when that's complete." \
| gh $OBJECTTYPE comment $OBJECTNR --body-file -