-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcreate_new_issue.ts
More file actions
102 lines (97 loc) · 3.3 KB
/
create_new_issue.ts
File metadata and controls
102 lines (97 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { DefineWorkflow, Schema } from "@slack/sdk";
import { CreateIssueDefinition } from "../functions/create_issue.ts";
/**
* A workflow is a set of steps that are executed in order. Each step in a
* workflow is a function – either a built-in or custom function.
* Learn more: https://api.slack.com/automation/workflows
*/
const CreateNewIssueWorkflow = DefineWorkflow({
callback_id: "create_new_issue_workflow",
title: "Create new issue",
description: "Create a new GitHub issue",
input_parameters: {
properties: {
/**
* This workflow users interactivity to collect input from the user.
* Learn more: https://api.slack.com/automation/forms#add-interactivity
*/
interactivity: {
type: Schema.slack.types.interactivity,
},
channel: {
type: Schema.slack.types.channel_id,
},
},
required: ["interactivity", "channel"],
},
});
/**
* Collecting input from users can be done with the built-in OpenForm function
* as the first step.
* Learn more: https://api.slack.com/automation/functions#open-a-form
*/
const issueFormData = CreateNewIssueWorkflow.addStep(
Schema.slack.functions.OpenForm,
{
title: "Create an issue",
interactivity: CreateNewIssueWorkflow.inputs.interactivity,
submit_label: "Create",
description: "Create a new issue inside of a GitHub repository",
fields: {
elements: [{
name: "url",
title: "Repository URL",
description: "The GitHub URL of the repository",
type: Schema.types.string,
format: "url",
}, {
name: "title",
title: "Issue title",
type: Schema.types.string,
}, {
name: "description",
title: "Issue description",
type: Schema.types.string,
long: true,
}, {
name: "assignees",
title: "Issue assignees",
description:
"GitHub username(s) of the user(s) to assign the issue to (separated by commas)",
type: Schema.types.string,
}],
required: ["url", "title"],
},
},
);
/**
* A custom function can be added as a workflow step to modify input data,
* interact with an external API, and return responses from the API for use in
* later steps.
* Learn more: https://api.slack.com/automation/functions/custom
*/
const issue = CreateNewIssueWorkflow.addStep(CreateIssueDefinition, {
/**
* The credential source defines which external authentication tokens are
* passed to the function. These are automatically injected at runtime.
* Learn more: https://api.slack.com/automation/external-auth#workflow
*/
githubAccessTokenId: {
credential_source: "DEVELOPER",
},
url: issueFormData.outputs.fields.url,
title: issueFormData.outputs.fields.title,
description: issueFormData.outputs.fields.description,
assignees: issueFormData.outputs.fields.assignees,
});
/**
* Messages can be sent into a channel with the built-in SendMessage function.
* Learn more: https://api.slack.com/automation/functions#catalog
*/
CreateNewIssueWorkflow.addStep(Schema.slack.functions.SendMessage, {
channel_id: CreateNewIssueWorkflow.inputs.channel,
message:
`Issue #${issue.outputs.GitHubIssueNumber} has been successfully created\n` +
`Link to issue: <${issue.outputs.GitHubIssueLink}>`,
});
export default CreateNewIssueWorkflow;