-
Notifications
You must be signed in to change notification settings - Fork 9
55 lines (45 loc) · 2.72 KB
/
kpi.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
name: count activity by non-members this month
on:
push: # to delete
workflow_dispatch:
jobs:
count-activity:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Count issues and PRs activity by non-members with pagination
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Function to paginate through API results
function paginate() {
url=$1
all_data="[]"
while [ -n "$url" ]; do
response=$(curl -H "Authorization: token $GITHUB_TOKEN" -s -I "$url")
data=$(curl -H "Authorization: token $GITHUB_TOKEN" -s "$url")
all_data=$(echo "$all_data$data" | jq -s add)
next_link=$(echo "$response" | grep -oP '(?<=<)(.*?)(?=>; rel="next")')
url=${next_link:+$next_link}
done
echo "$all_data"
}
# Get the first day of the current month
month_start=$(date -u +"%Y-%m-01T00:00:00Z")
# Pagination for opened issues
opened_issues_data=$(paginate "https://api.github.com/repos/${{ github.repository }}/issues?state=open&since=$month_start")
opened_issues_count=$(echo "$opened_issues_data" | jq '[.[] | select(.author_association != "MEMBER") and select(.author_association != "OWNER") and (.pull_request == null)] | length')
# Pagination for opened PRs
opened_prs_data=$(paginate "https://api.github.com/repos/${{ github.repository }}/pulls?state=open&since=$month_start")
opened_prs_count=$(echo "$opened_prs_data" | jq '[.[] | select(.author_association != "MEMBER") and select(.author_association != "OWNER")] | length')
# Pagination for closed issues
closed_issues_data=$(paginate "https://api.github.com/repos/${{ github.repository }}/issues?state=closed")
closed_issues_count=$(echo "$closed_issues_data" | jq '[.[] | select(.closed_at >= "'$month_start'") and select(.author_association != "MEMBER") and select(.author_association != "OWNER") and (.pull_request == null)] | length')
# Pagination for closed PRs
closed_prs_data=$(paginate "https://api.github.com/repos/${{ github.repository }}/pulls?state=closed")
closed_prs_count=$(echo "$closed_prs_data" | jq '[.[] | select(.closed_at >= "'$month_start'") and select(.author_association != "MEMBER") and select(.author_association != "OWNER")] | length')
echo "Number of issues opened by non-members this month: $opened_issues_count"
echo "Number of PRs opened by non-members this month: $opened_prs_count"
echo "Number of issues closed by non-members this month: $closed_issues_count"
echo "Number of PRs closed by non-members this month: $closed_prs_count"