Added GitHub getIssue Task (with example Job)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/github": patch
|
||||
---
|
||||
|
||||
Added getIssue Task
|
||||
@@ -52,6 +52,46 @@ client.defineJob({
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "new-github-issue-reminder",
|
||||
name: "New GitHub issue reminder",
|
||||
version: "0.1.0",
|
||||
integrations: { github, slack },
|
||||
trigger: github.triggers.repo({
|
||||
event: events.onIssueOpened,
|
||||
owner: "triggerdotdev",
|
||||
repo: "empty",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
//delay for 24 hours (or 60 seconds in development)
|
||||
const delayDuration =
|
||||
ctx.environment.type === "DEVELOPMENT" ? 60 : 60 * 60 * 24;
|
||||
await io.wait("wait 24 hours", delayDuration);
|
||||
|
||||
const issue = await io.github.getIssue("get issue", {
|
||||
owner: payload.repository.owner.login,
|
||||
repo: payload.repository.name,
|
||||
issueNumber: payload.issue.number,
|
||||
});
|
||||
|
||||
//if the issue has had no activity
|
||||
if (issue.updated_at === payload.issue.updated_at) {
|
||||
await io.slack.postMessage("Slack reminder", {
|
||||
text: `New issue needs attention: <${issue.html_url}|${issue.title}>`,
|
||||
channel: "C04GWUTDC3W",
|
||||
});
|
||||
|
||||
//assign it to someone, in this case… me
|
||||
await io.github.addIssueAssignees("add assignee", {
|
||||
owner: payload.repository.owner.login,
|
||||
repo: payload.repository.name,
|
||||
issueNumber: payload.issue.number,
|
||||
assignees: ["ericallam"],
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
client.defineJob({
|
||||
id: "github-integration-on-issue-assigned",
|
||||
name: "GitHub Integration - On Issue assigned",
|
||||
|
||||
@@ -166,6 +166,29 @@ const createIssueComment: GithubAuthenticatedTask<
|
||||
},
|
||||
};
|
||||
|
||||
const getIssue: GithubAuthenticatedTask<
|
||||
{ owner: string; repo: string; issueNumber: number },
|
||||
OctokitClient["rest"]["issues"]["get"]
|
||||
> = {
|
||||
onError,
|
||||
run: async (params, client) => {
|
||||
return client.rest.issues
|
||||
.get({
|
||||
owner: params.owner,
|
||||
repo: params.repo,
|
||||
issue_number: params.issueNumber,
|
||||
})
|
||||
.then((res) => res.data);
|
||||
},
|
||||
init: (params) => {
|
||||
return {
|
||||
name: "Get Issue",
|
||||
params,
|
||||
properties: [...repoProperties(params), ...issueProperties(params)],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const getRepo: GithubAuthenticatedTask<
|
||||
{ owner: string; repo: string },
|
||||
OctokitClient["rest"]["repos"]["get"]
|
||||
@@ -586,6 +609,7 @@ export const tasks = {
|
||||
addIssueAssignees,
|
||||
addIssueLabels,
|
||||
createIssueComment,
|
||||
getIssue,
|
||||
getRepo,
|
||||
createIssueCommentWithReaction,
|
||||
addIssueCommentReaction,
|
||||
|
||||
Reference in New Issue
Block a user