|
| 1 | +name: SAP Community profile URL requester |
| 2 | + |
| 3 | +# What the execution context is: |
| 4 | +# The assignment of a label to an issue or pull request indicating |
| 5 | +# that the contribution was valuable. |
| 6 | + |
| 7 | +# What it does: |
| 8 | +# Adds a comment to the issue or pull request asking the author for |
| 9 | +# their SAP Community profile URL ('community ID'). |
| 10 | + |
| 11 | +# Why we need it: |
| 12 | +# So that we can properly recognize the contribution in SAP Community. |
| 13 | + |
| 14 | +# What's important to know: |
| 15 | +# The label is specified at the start of the 'community-id-requester' |
| 16 | +# job as an environment variable LABEL, and also in the job-level condition. |
| 17 | +# Also, it adds a comment only after the first time the label is added, and |
| 18 | +# only if there are no other issues / pull requests already labeled. |
| 19 | + |
| 20 | +on: |
| 21 | + pull_request_target: |
| 22 | + types: [labeled] |
| 23 | + issues: |
| 24 | + types: [labeled] |
| 25 | + |
| 26 | +jobs: |
| 27 | + |
| 28 | + community-id-requester: |
| 29 | + |
| 30 | + env: |
| 31 | + LABEL: "contribution" |
| 32 | + runs-on: ubuntu-20.04 |
| 33 | + if: contains(github.repositoryUrl, 'github.com') && github.event.label.name == 'contribution' |
| 34 | + |
| 35 | + steps: |
| 36 | + |
| 37 | + - id: token_gen |
| 38 | + name: Generate app installation token |
| 39 | + uses: machine-learning-apps/[email protected] |
| 40 | + with: |
| 41 | + APP_PEM: ${{ secrets.SAP_TUTORIALS_APP_PEM_BASE64 }} |
| 42 | + APP_ID: ${{ secrets.SAP_TUTORIALS_APP_ID }} |
| 43 | + |
| 44 | + - id: checkout |
| 45 | + name: Check out the repo |
| 46 | + uses: actions/checkout@v2 |
| 47 | + with: |
| 48 | + token: ${{ steps.token_gen.outputs.app_token }} |
| 49 | + |
| 50 | + - id: issue_details |
| 51 | + name: Determine related details if issue |
| 52 | + if: github.event_name == 'issues' |
| 53 | + run: | |
| 54 | + echo "OBJECTTYPE=issue" >> $GITHUB_ENV |
| 55 | + echo "CONTRIBUTIONTYPE=feedback" >> $GITHUB_ENV |
| 56 | + echo "OBJECTNR=${{ github.event.issue.number }}" >> $GITHUB_ENV |
| 57 | + echo "CONTRIBUTOR=${{ github.event.issue.user.login }}" >> $GITHUB_ENV |
| 58 | + - id: pull_request_details |
| 59 | + name: Determine related details if pull request |
| 60 | + if: github.event_name == 'pull_request_target' |
| 61 | + run: | |
| 62 | + echo "OBJECTTYPE=pr" >> $GITHUB_ENV |
| 63 | + echo "CONTRIBUTIONTYPE=content" >> $GITHUB_ENV |
| 64 | + echo "OBJECTNR=${{ github.event.pull_request.number }}" >> $GITHUB_ENV |
| 65 | + echo "CONTRIBUTOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV |
| 66 | + - id: auth_gh |
| 67 | + name: Authenticate gh to repo |
| 68 | + run: echo -n ${{ steps.token_gen.outputs.app_token }} | gh auth login --with-token |
| 69 | + |
| 70 | + - id: count_label_additions |
| 71 | + name: Count number of times label has been added |
| 72 | + run: | |
| 73 | + endpoint="repos/${{ github.repository }}/issues/$OBJECTNR/events" |
| 74 | + count=$(gh api --jq "[.[]|(select(.event==\"labeled\" and .label.name==\"$LABEL\"))] | length" $endpoint) |
| 75 | + echo "LABELADDITIONCOUNT=$count" >> $GITHUB_ENV |
| 76 | + - id: count_previous_labeled_objects |
| 77 | + name: Count how many other issues / pull requests are so labeled |
| 78 | + run: | |
| 79 | + querystring="is:${OBJECTTYPE}+label:${LABEL}+author:${CONTRIBUTOR}+repo:${GITHUB_REPOSITORY}" |
| 80 | + result=$(gh api --jq '.items[] | [.number, .title] | @tsv' "/search/issues?q=$querystring") |
| 81 | + echo "$result" |
| 82 | + echo "OBJECTCOUNT=$(wc -l <<< $result)" | tee -a $GITHUB_ENV |
| 83 | + - id: requester |
| 84 | + name: Ask for SAP Community profile URL if label added for first time and no prev labeled issue / pr |
| 85 | + if: env.LABELADDITIONCOUNT == 1 && env.OBJECTCOUNT <= 1 |
| 86 | + run: | |
| 87 | + printf "Thank you for your valuable ${CONTRIBUTIONTYPE} contribution, @${CONTRIBUTOR}! So that we can [recognize your contribution in SAP Community](https://github.com/SAP-docs/contribution-guidelines/blob/main/docs/recognition.md), please tell us your SAP Community profile URL in a reply to this comment; don't include any other text, just the URL on its own, like this:\n\n\`\`\`\nhttps://people.sap.com/your-user-name\n\`\`\`\n\nThanks!" \ |
| 88 | + | gh $OBJECTTYPE comment $OBJECTNR --body-file - |
0 commit comments