Skip to content

Commit 2d7ffcc

Browse files
committed
feat(comment): ✨ add success comment posting for deployments
* implements `postSuccessComment` to notify on successful deployments * updates release body or comments on PRs as appropriate * enhances user feedback during deployment process
1 parent 88c9fbc commit 2d7ffcc

3 files changed

Lines changed: 147 additions & 1 deletion

File tree

build/index.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32900,6 +32900,71 @@ async function openFailureIssue(githubToken, context, details) {
3290032900
await octokit.rest.issues.create({ owner, repo, title, body });
3290132901
}
3290232902

32903+
async function postSuccessComment(githubToken, context, details) {
32904+
if (!githubToken) {
32905+
core.info('No GitHub token available to post success comment.');
32906+
return;
32907+
}
32908+
const octokit = github.getOctokit(githubToken);
32909+
const { owner, repo } = context.repo;
32910+
const body = [
32911+
`✅ Coswarm deploy succeeded for ${details.image}`,
32912+
'',
32913+
`**API URL:** ${details.apiUrl}`,
32914+
`**Image:** ${details.image}`,
32915+
].join('\n');
32916+
32917+
// If run from a release event, update the release body with a note
32918+
if (context.payload && context.payload.release && context.payload.release.tag_name) {
32919+
const tag = context.payload.release.tag_name;
32920+
try {
32921+
const rel = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });
32922+
const newBody = `${rel.data.body || ''}\n\n${body}`;
32923+
await octokit.rest.repos.updateRelease({
32924+
owner,
32925+
repo,
32926+
release_id: rel.data.id,
32927+
body: newBody,
32928+
});
32929+
return;
32930+
} catch (err) {
32931+
core.warning(`Could not update release: ${err.message}`);
32932+
}
32933+
}
32934+
32935+
// If triggered by a pull request, comment on the PR
32936+
if (context.payload && context.payload.pull_request && context.payload.pull_request.number) {
32937+
try {
32938+
await octokit.rest.issues.createComment({
32939+
owner,
32940+
repo,
32941+
issue_number: context.payload.pull_request.number,
32942+
body,
32943+
});
32944+
return;
32945+
} catch (err) {
32946+
core.warning(`Could not create PR comment: ${err.message}`);
32947+
}
32948+
}
32949+
32950+
// Fall back to commit comment if we have a SHA
32951+
if (context.sha) {
32952+
try {
32953+
await octokit.rest.repos.createCommitComment({
32954+
owner,
32955+
repo,
32956+
commit_sha: context.sha,
32957+
body,
32958+
});
32959+
return;
32960+
} catch (err) {
32961+
core.warning(`Could not create commit comment: ${err.message}`);
32962+
}
32963+
}
32964+
32965+
core.info('No suitable target found to post success comment; skipping.');
32966+
}
32967+
3290332968
async function run() {
3290432969
let image = '';
3290532970
let baseUrl = '';
@@ -32916,6 +32981,14 @@ async function run() {
3291632981
core.info(`Triggering deploy via ${apiUrl}`);
3291732982
const responseBody = await triggerDeploy(apiUrl, token, image);
3291832983
core.setOutput('response', responseBody);
32984+
try {
32985+
await postSuccessComment(githubToken, github.context, {
32986+
apiUrl,
32987+
image,
32988+
});
32989+
} catch (postErr) {
32990+
core.warning(`Failed to post success comment: ${postErr.message}`);
32991+
}
3291932992
} catch (error) {
3292032993
core.setFailed(error.message);
3292132994
await openFailureIssue(githubToken, github.context, {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coswarm-deploy-action",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "GitHub Action that triggers Coswarm deployments and files issues on failure.",
55
"main": "build/index.js",
66
"scripts": {

src/index.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,71 @@ async function openFailureIssue(githubToken, context, details) {
6262
await octokit.rest.issues.create({ owner, repo, title, body });
6363
}
6464

65+
async function postSuccessComment(githubToken, context, details) {
66+
if (!githubToken) {
67+
core.info('No GitHub token available to post success comment.');
68+
return;
69+
}
70+
const octokit = github.getOctokit(githubToken);
71+
const { owner, repo } = context.repo;
72+
const body = [
73+
`✅ Coswarm deploy succeeded for ${details.image}`,
74+
'',
75+
`**API URL:** ${details.apiUrl}`,
76+
`**Image:** ${details.image}`,
77+
].join('\n');
78+
79+
// If run from a release event, update the release body with a note
80+
if (context.payload && context.payload.release && context.payload.release.tag_name) {
81+
const tag = context.payload.release.tag_name;
82+
try {
83+
const rel = await octokit.rest.repos.getReleaseByTag({ owner, repo, tag });
84+
const newBody = `${rel.data.body || ''}\n\n${body}`;
85+
await octokit.rest.repos.updateRelease({
86+
owner,
87+
repo,
88+
release_id: rel.data.id,
89+
body: newBody,
90+
});
91+
return;
92+
} catch (err) {
93+
core.warning(`Could not update release: ${err.message}`);
94+
}
95+
}
96+
97+
// If triggered by a pull request, comment on the PR
98+
if (context.payload && context.payload.pull_request && context.payload.pull_request.number) {
99+
try {
100+
await octokit.rest.issues.createComment({
101+
owner,
102+
repo,
103+
issue_number: context.payload.pull_request.number,
104+
body,
105+
});
106+
return;
107+
} catch (err) {
108+
core.warning(`Could not create PR comment: ${err.message}`);
109+
}
110+
}
111+
112+
// Fall back to commit comment if we have a SHA
113+
if (context.sha) {
114+
try {
115+
await octokit.rest.repos.createCommitComment({
116+
owner,
117+
repo,
118+
commit_sha: context.sha,
119+
body,
120+
});
121+
return;
122+
} catch (err) {
123+
core.warning(`Could not create commit comment: ${err.message}`);
124+
}
125+
}
126+
127+
core.info('No suitable target found to post success comment; skipping.');
128+
}
129+
65130
async function run() {
66131
let image = '';
67132
let baseUrl = '';
@@ -78,6 +143,14 @@ async function run() {
78143
core.info(`Triggering deploy via ${apiUrl}`);
79144
const responseBody = await triggerDeploy(apiUrl, token, image);
80145
core.setOutput('response', responseBody);
146+
try {
147+
await postSuccessComment(githubToken, github.context, {
148+
apiUrl,
149+
image,
150+
});
151+
} catch (postErr) {
152+
core.warning(`Failed to post success comment: ${postErr.message}`);
153+
}
81154
} catch (error) {
82155
core.setFailed(error.message);
83156
await openFailureIssue(githubToken, github.context, {

0 commit comments

Comments
 (0)