mirror of
https://github.com/hernikplays/freelo-action.git
synced 2024-11-24 08:41:05 +01:00
feat: implement reopened
This commit is contained in:
parent
e033a1d4b5
commit
781de57aca
2 changed files with 61 additions and 3 deletions
22
dist/index.js
vendored
22
dist/index.js
vendored
|
@ -45417,8 +45417,28 @@ try {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "reopened":
|
||||
case "reopened": {
|
||||
const comment2 = (await octokit.rest.issues.listComments({
|
||||
...github.context.repo,
|
||||
issue_number: issue.number,
|
||||
mediaType: {
|
||||
format: "html"
|
||||
}
|
||||
})).data.filter((i) => i.user?.type === "Bot" && i.user.login === "github-actions[bot]");
|
||||
if (comment2.length === 0)
|
||||
break;
|
||||
const taskId2 = /https:\/\/app.freelo.io\/task\/(\d+)/.exec(comment2[0].body_html ?? "");
|
||||
if (!taskId2 || taskId2.length === 0) {
|
||||
console.log("Comment found, but no Freelo task ID identified");
|
||||
break;
|
||||
}
|
||||
const res = await axios_default.post(`${apiEndpoint}/task/${taskId2[1]}/activate`, null, defaultOptions);
|
||||
if (res.status > 399) {
|
||||
console.error(res.data);
|
||||
throw new Error("Got an error response from Freelo API");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "assigned":
|
||||
break;
|
||||
case "unassigned":
|
||||
|
|
42
src/index.ts
42
src/index.ts
|
@ -62,6 +62,7 @@ function freeloMention(username: string): string {
|
|||
|
||||
try {
|
||||
if (!action) {
|
||||
// TODO: Is run manually, check all issues
|
||||
throw new Error("No action was passed");
|
||||
}
|
||||
if (!email || !apiKey || !projectId) {
|
||||
|
@ -133,7 +134,8 @@ try {
|
|||
},
|
||||
})
|
||||
).data.filter(
|
||||
(i) => i.user?.type === "Bot" && i.user.login === "github-actions[bot]",
|
||||
(i) =>
|
||||
i.user?.type === "Bot" && i.user.login === "github-actions[bot]",
|
||||
);
|
||||
if (comment.length === 0) break; // not a Freelo task, skip
|
||||
|
||||
|
@ -157,8 +159,44 @@ try {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "reopened":
|
||||
case "reopened": {
|
||||
// Get comments and find the related Freelo task ID
|
||||
const comment = (
|
||||
await octokit.rest.issues.listComments({
|
||||
...context.repo,
|
||||
issue_number: issue.number,
|
||||
mediaType: {
|
||||
format: "html",
|
||||
},
|
||||
})
|
||||
).data.filter(
|
||||
(i) =>
|
||||
i.user?.type === "Bot" && i.user.login === "github-actions[bot]",
|
||||
);
|
||||
if (comment.length === 0) break; // not a Freelo task, skip
|
||||
|
||||
// Finish task in Freelo
|
||||
const taskId = /https:\/\/app.freelo.io\/task\/(\d+)/.exec(
|
||||
comment[0].body_html ?? "",
|
||||
);
|
||||
if (!taskId || taskId.length === 0) {
|
||||
console.log("Comment found, but no Freelo task ID identified");
|
||||
break;
|
||||
}
|
||||
|
||||
// Reactivate
|
||||
const res = await axios.post(
|
||||
`${apiEndpoint}/task/${taskId[1]}/activate`,
|
||||
null,
|
||||
defaultOptions,
|
||||
);
|
||||
|
||||
if (res.status > 399) {
|
||||
console.error(res.data);
|
||||
throw new Error("Got an error response from Freelo API");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "assigned":
|
||||
break;
|
||||
case "unassigned":
|
||||
|
|
Loading…
Reference in a new issue