22permissions :
33 contents : read
44 issues : write
5+ pull-requests : read
56
67on :
78 pull_request :
@@ -17,30 +18,111 @@ jobs:
1718 runs-on : ubuntu-latest
1819
1920 steps :
21+ - name : Checkout repository
22+ uses : actions/checkout@v4
23+ with :
24+ fetch-depth : 10
25+
26+ - name : Extract and prepare release notes
27+ id : prepare_notes
28+ env :
29+ GH_TOKEN : ${{ github.token }}
30+ run : |
31+ set -eo pipefail
32+
33+ # Function to extract release notes from PR body
34+ extract_release_notes() {
35+ local body="$1"
36+
37+ # Remove "Summary by CodeRabbit" section and auto-generated comment line
38+ local cleaned_body="$(printf '%s\n' "$body" \
39+ | grep -v '<!-- end of auto-generated comment: release notes by coderabbit.ai -->' \
40+ | awk '
41+ BEGIN { skip=0 }
42+ /^## Summary by CodeRabbit/ { skip=1; next }
43+ /^## / && skip==1 { skip=0 }
44+ skip==0 { print }
45+ ')"
46+
47+ # Try to extract content under "## Release Notes" heading
48+ local notes="$(printf '%s\n' "$cleaned_body" \
49+ | awk 'f && /^## /{exit} /^## Release Notes/{f=1; next} f')"
50+
51+ # If no specific section found, use the entire cleaned body
52+ if [ -z "$notes" ]; then
53+ notes="$cleaned_body"
54+ fi
55+
56+ printf '%s\n' "$notes"
57+ }
58+
59+ echo "Fetching PR #${{ github.event.pull_request.number }} details..."
60+
61+ # Fetch the PR body using GitHub CLI
62+ PR_BODY=$(gh pr view "${{ github.event.pull_request.number }}" --json body --jq '.body' 2>/dev/null || echo "")
63+
64+ NOTES=""
65+ if [ -n "$PR_BODY" ]; then
66+ echo "PR body found, extracting release notes..."
67+ NOTES="$(extract_release_notes "$PR_BODY")"
68+ fi
69+
70+ # Fallback to PR title and recent commits if no body found
71+ if [ -z "$NOTES" ] || [ "$NOTES" = "" ]; then
72+ echo "No PR body found, using PR title and commits..."
73+ NOTES="## ${{ github.event.pull_request.title }}"
74+ NOTES="$NOTES"$'\n\n'"$(git log -n 5 --pretty=format:'- %s')"
75+ fi
76+
77+ # Save to file and environment
78+ echo "$NOTES" > release_notes.txt
79+
80+ # For multiline output, use delimiter
81+ {
82+ echo 'RELEASE_NOTES<<EOF'
83+ echo "$NOTES"
84+ echo 'EOF'
85+ } >> "$GITHUB_OUTPUT"
86+
87+ echo "Release notes prepared:"
88+ cat release_notes.txt
89+
2090 - name : Post to Changerawr API
2191 uses : actions/github-script@v7
2292 env :
2393 CHANGERAWR_API_KEY : ${{ secrets.CHANGERAWR_API_KEY }}
2494 CHANGERAWR_PROJECT_ID : ${{ secrets.CHANGERAWR_PROJECT_ID }}
95+ RELEASE_NOTES : ${{ steps.prepare_notes.outputs.RELEASE_NOTES }}
2596 with :
2697 script : |
27- const prBody = context.payload.pull_request.body || '';
2898 const prNumber = context.payload.pull_request.number;
2999 const prTitle = context.payload.pull_request.title;
30100 const prUrl = context.payload.pull_request.html_url;
101+ const releaseNotes = process.env.RELEASE_NOTES || '';
102+
103+ // Check if required secrets are set
104+ if (!process.env.CHANGERAWR_API_KEY || !process.env.CHANGERAWR_PROJECT_ID) {
105+ console.log('⚠️ Changerawr API credentials not configured, skipping release notes submission');
106+ return;
107+ }
31108
32109 // Prepare the payload for Changerawr API
33110 const payload = {
34- notes: prBody,
111+ title: prTitle,
112+ content: releaseNotes,
35113 metadata: {
36114 pr_number: prNumber,
37115 pr_title: prTitle,
38116 pr_url: prUrl,
39117 merged_at: context.payload.pull_request.merged_at,
40- merged_by: context.payload.pull_request.merged_by?.login || 'unknown'
118+ merged_by: context.payload.pull_request.merged_by?.login || 'unknown',
119+ commit_sha: context.payload.pull_request.merge_commit_sha
41120 }
42121 };
43122
123+ console.log('Sending release notes to Changerawr...');
124+ console.log('Payload:', JSON.stringify(payload, null, 2));
125+
44126 try {
45127 const response = await fetch(
46128 `https://clog.resgrid.com/api/projects/${process.env.CHANGERAWR_PROJECT_ID}/changelog`,
@@ -54,23 +136,36 @@ jobs:
54136 }
55137 );
56138
139+ const responseText = await response.text();
140+
57141 if (!response.ok) {
58- const errorText = await response.text();
59- throw new Error(`Changerawr API request failed: ${response.status} - ${errorText}`);
142+ console.warn(`⚠️ Changerawr API request failed: ${response.status} - ${responseText}`);
143+ // Don't fail the workflow, just log the error
144+ return;
60145 }
61146
62- const result = await response.json();
63- console.log('Successfully posted to Changerawr:', result);
147+ let result;
148+ try {
149+ result = JSON.parse(responseText);
150+ } catch (e) {
151+ result = responseText;
152+ }
153+
154+ console.log('✅ Successfully posted to Changerawr:', result);
64155
65156 // Optionally, comment on the PR with confirmation
66- await github.rest.issues.createComment({
67- owner: context.repo.owner,
68- repo: context.repo.repo,
69- issue_number: prNumber,
70- body: '✅ Change notes have been posted to Changerawr.'
71- });
157+ try {
158+ await github.rest.issues.createComment({
159+ owner: context.repo.owner,
160+ repo: context.repo.repo,
161+ issue_number: prNumber,
162+ body: '✅ Change notes have been posted to Changerawr.'
163+ });
164+ } catch (commentError) {
165+ console.log('Could not post comment to PR:', commentError.message);
166+ }
72167
73168 } catch (error) {
74- console.error('Error posting to Changerawr:', error);
75- core.setFailed(`Failed to post to Changerawr: ${error.message}`);
169+ console.error('⚠️ Error posting to Changerawr:', error);
170+ // Don't fail the workflow
76171 }
0 commit comments