forked from ton-society/gh-ton-contribution-reward
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
114 lines (94 loc) · 4.06 KB
/
action.yml
File metadata and controls
114 lines (94 loc) · 4.06 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: "Allowlist GitHub User"
description: "This action sends a POST request to add a new entry in TON Society ID Github allowlist when a given Github user's PR is merged."
inputs:
github_token:
description: "GitHub token to comment on PR"
required: true
x_api_key:
description: "API key for authentication"
required: true
x_partner_id:
description: "Partner ID for authentication"
required: true
github_pr_number:
description: "The Pull Request number where to leave a comment with the reward link"
required: true
activity_id:
description: "The activity ID"
required: true
xps:
description: "Optional reward xps"
required: false
runs:
using: "composite"
steps:
- name: Install jq
shell: bash
run: sudo apt-get install jq -y
- name: Get PR Author's GitHub User ID and Login
id: pr_author
shell: bash
run: |
pr_data=$(curl -s -H "Authorization: Bearer ${{ inputs.github_token }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ inputs.github_pr_number }}")
pr_author_id=$(echo "$pr_data" | jq -r '.user.id')
pr_author_login=$(echo "$pr_data" | jq -r '.user.login // empty')
echo "PR Author's GitHub ID: $pr_author_id"
echo "PR Author's Login: $pr_author_login"
echo "pr_author_id=$pr_author_id" >> "$GITHUB_ENV"
echo "pr_author_login=$pr_author_login" >> "$GITHUB_ENV"
- name: Call Allowlist API and store reward link
id: call_api
shell: bash
run: |
if [[ -n "${{ inputs.xps }}" ]]; then
echo "ℹ️ Including xps value: ${{ inputs.xps }}"
request_body=$(jq -n \
--arg xps "${{ inputs.xps }}" \
'{attributes: [{trait_type: "xps", value: $xps}]}')
else
echo "ℹ️ No xps provided. Sending empty request body."
request_body="{}"
fi
echo "➡️ Sending POST request..."
curl_output=$(mktemp)
http_code=$(curl -s -o "$curl_output" -w "%{http_code}" -X POST "https://society.ton.org/v1/activities/${{ inputs.activity_id }}/allowlist/github-ids/${{ env.pr_author_id }}" \
-H "x-api-key: ${{ inputs.x_api_key }}" \
-H "x-partner-id: ${{ inputs.x_partner_id }}" \
-H "Content-Type: application/json" \
-d "$request_body")
http_body=$(cat "$curl_output")
echo "HTTP status: $http_code"
echo "Response body: $http_body"
if [[ "$http_code" -lt 200 || "$http_code" -ge 300 ]]; then
echo "❌ API call failed with status $http_code"
exit 1
fi
reward_link=$(echo "$http_body" | jq -r '.data.reward_link_url // empty')
if [ -z "$reward_link" ]; then
echo "❌ reward_link_url not found in response."
exit 1
fi
echo "✅ Received reward link: $reward_link"
echo "reward_link_url=$reward_link" >> "$GITHUB_OUTPUT"
- name: Comment reward link on PR
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
run: |
repo="${{ github.repository }}"
reward_link="${{ steps.call_api.outputs.reward_link_url }}"
if [ -z "$reward_link" ]; then
echo "⚠️ No reward link to comment. Skipping comment step."
exit 0
fi
comment_body="🎉 Hi there, thanks for your contribution! Here’s your reward [link]($reward_link). Receive more rewards and grow your reputation in the TON Developers league"
pr_author="${{ env.pr_author_login }}"
if [ -z "$pr_author" ]; then
comment_body="🎉 Hey there @${pr_author}, thanks for your contribution! Here’s your reward [link]($reward_link). Receive more rewards and grow your reputation in the TON Developers league"
fi
curl -s -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg body "$comment_body" '{body: $body}')" \
"https://api.github.com/repos/$repo/issues/${{ inputs.github_pr_number }}/comments"