Skip to content

Commit f8aff90

Browse files
authored
chore/change-api (#2144)
1 parent 1c5edad commit f8aff90

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

.github/workflows/repo-stats.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
GH_REPO: ${{ github.repository }}
3232
GH_SERVER: ${{ github.server_url }}
3333
DAYS_RAW: ${{ github.event.inputs.days || 7 }}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3435
run: |
3536
# Clamp days to 1–365
3637
DAYS=$DAYS_RAW
@@ -51,15 +52,21 @@ jobs:
5152
echo "::group::Debug: API request and response"
5253
echo "Repo: $GH_REPO | START: $START | END: $END"
5354
echo "API base: $API"
54-
PULLS_RESP=$(curl -sS -w "\n%{http_code}" -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "${API}/pulls?state=closed&per_page=5")
55+
PULLS_RESP=$(curl -sS -w "\n%{http_code}" -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" "${API}/pulls?state=closed&per_page=5")
5556
PULLS_BODY=$(echo "$PULLS_RESP" | head -n -1)
5657
PULLS_CODE=$(echo "$PULLS_RESP" | tail -n1)
5758
echo "GET /pulls?state=closed&per_page=5 → HTTP $PULLS_CODE"
59+
if [[ "$PULLS_CODE" != "200" ]]; then
60+
echo "⚠️ Non-200 response. Common cause: workflow run from a *fork* (GITHUB_TOKEN cannot read the main repo)."
61+
echo " Fix: Ensure the workflow runs from the main repo (shopware/docs), not a fork."
62+
fi
5863
echo "$PULLS_BODY" > /tmp/debug_pulls.json
59-
if echo "$PULLS_BODY" | jq -e . >/dev/null 2>&1; then
60-
echo "Response is valid JSON. Array length: $(echo "$PULLS_BODY" | jq 'length')"
61-
echo "First item keys: $(echo "$PULLS_BODY" | jq -r '.[0] | keys | join(", ")')"
62-
echo "First item merged_at: $(echo "$PULLS_BODY" | jq -r '.[0].merged_at // "null"')"
64+
if echo "$PULLS_BODY" | jq -e 'type == "array"' >/dev/null 2>&1; then
65+
echo "Response is JSON array. Length: $(echo "$PULLS_BODY" | jq 'length')"
66+
if [[ "$(echo "$PULLS_BODY" | jq 'length')" -gt 0 ]]; then
67+
echo "First item keys: $(echo "$PULLS_BODY" | jq -r '.[0] | keys | join(", ")')"
68+
echo "First item merged_at: $(echo "$PULLS_BODY" | jq -r '.[0].merged_at // "null"')"
69+
fi
6370
echo "First 800 chars of response:"
6471
echo "$PULLS_BODY" | head -c 800
6572
echo ""
@@ -75,7 +82,7 @@ jobs:
7582
# Pull requests created (REST: created_at)
7683
echo "### Pull requests created" >> report.md
7784
echo "" >> report.md
78-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
85+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
7986
"${API}/pulls?state=all&sort=created&direction=desc&per_page=100" | \
8087
jq -r --arg start "$START" '.[] | select(.created_at[:10] >= $start) | "- [\(.state | ascii_upcase)] #\(.number) \(.title) (created: \(.created_at[:10]))"' > /tmp/pr_created.txt 2>/dev/null || true
8188
[ -s /tmp/pr_created.txt ] && cat /tmp/pr_created.txt >> report.md || echo "- No PRs in this period" >> report.md
@@ -84,7 +91,7 @@ jobs:
8491
# Pull requests merged (need to fetch closed PRs and filter by merged_at; REST /pulls only returns open+closed, merged_at is on each)
8592
echo "### Pull requests merged" >> report.md
8693
echo "" >> report.md
87-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
94+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
8895
"${API}/pulls?state=closed&sort=updated&direction=desc&per_page=100" | \
8996
jq -r --arg start "$START" '.[] | select(.merged_at != null and (.merged_at[:10] >= $start)) | "- #\(.number) \(.title) (merged: \(.merged_at[:10]))"' > /tmp/pr_merged.txt 2>/dev/null || true
9097
[ -s /tmp/pr_merged.txt ] && cat /tmp/pr_merged.txt >> report.md || echo "- No merged PRs in this period" >> report.md
@@ -93,7 +100,7 @@ jobs:
93100
# Issues opened (REST: created_at)
94101
echo "### Issues opened" >> report.md
95102
echo "" >> report.md
96-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
103+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
97104
"${API}/issues?state=all&sort=created&direction=desc&per_page=100" | \
98105
jq -r --arg start "$START" '.[] | select(.pull_request == null and .created_at[:10] >= $start) | "- [\(.state | ascii_upcase)] #\(.number) \(.title) (opened: \(.created_at[:10]))"' > /tmp/issue_opened.txt 2>/dev/null || true
99106
[ -s /tmp/issue_opened.txt ] && cat /tmp/issue_opened.txt >> report.md || echo "- No issues in this period" >> report.md
@@ -102,7 +109,7 @@ jobs:
102109
# Issues closed (REST: closed_at)
103110
echo "### Issues closed" >> report.md
104111
echo "" >> report.md
105-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
112+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
106113
"${API}/issues?state=closed&sort=updated&direction=desc&per_page=100" | \
107114
jq -r --arg start "$START" '.[] | select(.pull_request == null and .closed_at != null and (.closed_at[:10] >= $start)) | "- #\(.number) \(.title) (closed: \(.closed_at[:10]))"' > /tmp/issue_closed.txt 2>/dev/null || true
108115
[ -s /tmp/issue_closed.txt ] && cat /tmp/issue_closed.txt >> report.md || echo "- No closed issues in this period" >> report.md
@@ -113,28 +120,28 @@ jobs:
113120
echo "" >> slack_report.txt
114121
115122
echo "*Pull requests created*" >> slack_report.txt
116-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
123+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
117124
"${API}/pulls?state=all&sort=created&direction=desc&per_page=100" | \
118125
jq -r --arg start "$START" --arg base "$BASE" '.[] | select(.created_at[:10] >= $start) | "• <\($base)/pull/\(.number)|#\(.number)> \(.title) (_\(.state)_ \(.created_at[:10]))"' > /tmp/slack_pr_created.txt 2>/dev/null || true
119126
[ -s /tmp/slack_pr_created.txt ] && cat /tmp/slack_pr_created.txt >> slack_report.txt || echo "• _None_" >> slack_report.txt
120127
echo "" >> slack_report.txt
121128
122129
echo "*Pull requests merged*" >> slack_report.txt
123-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
130+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
124131
"${API}/pulls?state=closed&sort=updated&direction=desc&per_page=100" | \
125132
jq -r --arg start "$START" --arg base "$BASE" '.[] | select(.merged_at != null and (.merged_at[:10] >= $start)) | "• <\($base)/pull/\(.number)|#\(.number)> \(.title) (merged \(.merged_at[:10]))"' > /tmp/slack_pr_merged.txt 2>/dev/null || true
126133
[ -s /tmp/slack_pr_merged.txt ] && cat /tmp/slack_pr_merged.txt >> slack_report.txt || echo "• _None_" >> slack_report.txt
127134
echo "" >> slack_report.txt
128135
129136
echo "*Issues opened*" >> slack_report.txt
130-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
137+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
131138
"${API}/issues?state=all&sort=created&direction=desc&per_page=100" | \
132139
jq -r --arg start "$START" --arg base "$BASE" '.[] | select(.pull_request == null and .created_at[:10] >= $start) | "• <\($base)/issues/\(.number)|#\(.number)> \(.title) (_\(.state)_ \(.created_at[:10]))"' > /tmp/slack_issue_opened.txt 2>/dev/null || true
133140
[ -s /tmp/slack_issue_opened.txt ] && cat /tmp/slack_issue_opened.txt >> slack_report.txt || echo "• _None_" >> slack_report.txt
134141
echo "" >> slack_report.txt
135142
136143
echo "*Issues closed*" >> slack_report.txt
137-
curl -sS -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
144+
curl -sS -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3+json" \
138145
"${API}/issues?state=closed&sort=updated&direction=desc&per_page=100" | \
139146
jq -r --arg start "$START" --arg base "$BASE" '.[] | select(.pull_request == null and .closed_at != null and (.closed_at[:10] >= $start)) | "• <\($base)/issues/\(.number)|#\(.number)> \(.title) (closed \(.closed_at[:10]))"' > /tmp/slack_issue_closed.txt 2>/dev/null || true
140147
[ -s /tmp/slack_issue_closed.txt ] && cat /tmp/slack_issue_closed.txt >> slack_report.txt || echo "• _None_" >> slack_report.txt

0 commit comments

Comments
 (0)