Skip to content

Commit 1eb28bb

Browse files
authored
Add issue label add/remove actions (#90)
* Add issue label add/remove actions * Version bump
1 parent 24de042 commit 1eb28bb

File tree

3 files changed

+237
-1
lines changed

3 files changed

+237
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "linear-zapier",
3-
"version": "4.7.0",
3+
"version": "4.8.0",
44
"description": "Linear's Zapier integration",
55
"main": "index.js",
66
"license": "MIT",

src/creates/addIssueLabel.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Bundle, ZObject } from "zapier-platform-core";
2+
3+
type AddIssueLabelResponse = {
4+
data?: {
5+
issueAddLabel: {
6+
success: boolean;
7+
issue: {
8+
id: string;
9+
title: string;
10+
url: string;
11+
identifier: string;
12+
};
13+
};
14+
};
15+
errors?: {
16+
message: string;
17+
extensions?: {
18+
userPresentableMessage?: string;
19+
};
20+
}[];
21+
};
22+
23+
const addIssueLabelRequest = async (z: ZObject, bundle: Bundle) => {
24+
const query = `
25+
mutation ZapierIssueAddLabel(
26+
$issueId: String!,
27+
$labelId: String!
28+
) {
29+
issueAddLabel(
30+
id: $issueId,
31+
labelId: $labelId
32+
) {
33+
success
34+
issue {
35+
id
36+
identifier
37+
title
38+
url
39+
}
40+
}
41+
}`;
42+
43+
const variables = {
44+
issueId: bundle.inputData.issue_id,
45+
labelId: bundle.inputData.label_id,
46+
};
47+
48+
const response = await z.request({
49+
url: "https://api.linear.app/graphql",
50+
headers: {
51+
"Content-Type": "application/json",
52+
Accept: "application/json",
53+
authorization: bundle.authData.api_key,
54+
},
55+
body: {
56+
query,
57+
variables,
58+
},
59+
method: "POST",
60+
});
61+
62+
const data = response.json as AddIssueLabelResponse;
63+
64+
if (data.errors && data.errors.length) {
65+
const error = data.errors[0];
66+
throw new z.errors.Error(
67+
(error.extensions && error.extensions.userPresentableMessage) || error.message,
68+
"invalid_input",
69+
400
70+
);
71+
}
72+
73+
if (data.data && data.data.issueAddLabel && data.data.issueAddLabel.success) {
74+
return data.data.issueAddLabel.issue;
75+
} else {
76+
throw new z.errors.Error(`Failed to add label to issue`, "Something went wrong", 400);
77+
}
78+
};
79+
80+
export const addIssueLabel = {
81+
key: "add_issue_label",
82+
83+
display: {
84+
hidden: false,
85+
description: "Add a label to an existing issue in Linear",
86+
label: "Add Label to Issue",
87+
},
88+
89+
noun: "Label",
90+
91+
operation: {
92+
perform: addIssueLabelRequest,
93+
94+
inputFields: [
95+
{
96+
required: true,
97+
label: "Issue",
98+
key: "issue_id",
99+
dynamic: "issue.id.identifier",
100+
helpText: "The issue to add the label to",
101+
},
102+
{
103+
required: true,
104+
label: "Label",
105+
key: "label_id",
106+
dynamic: "label.id.name",
107+
helpText: "The label to add to the issue",
108+
},
109+
],
110+
111+
sample: {
112+
id: "7b647c45-c528-464d-8634-eecea0f73033",
113+
title: "Sample Issue",
114+
url: "https://linear.app/team-best-team/issue/ENG-123/sample-issue",
115+
identifier: "ENG-123",
116+
},
117+
},
118+
};

src/creates/removeIssueLabel.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Bundle, ZObject } from "zapier-platform-core";
2+
3+
type RemoveIssueLabelResponse = {
4+
data?: {
5+
issueRemoveLabel: {
6+
success: boolean;
7+
issue: {
8+
id: string;
9+
title: string;
10+
url: string;
11+
identifier: string;
12+
};
13+
};
14+
};
15+
errors?: {
16+
message: string;
17+
extensions?: {
18+
userPresentableMessage?: string;
19+
};
20+
}[];
21+
};
22+
23+
const removeIssueLabelRequest = async (z: ZObject, bundle: Bundle) => {
24+
const query = `
25+
mutation ZapierIssueRemoveLabel(
26+
$issueId: String!,
27+
$labelId: String!
28+
) {
29+
issueRemoveLabel(
30+
id: $issueId,
31+
labelId: $labelId
32+
) {
33+
success
34+
issue {
35+
id
36+
identifier
37+
title
38+
url
39+
}
40+
}
41+
}`;
42+
43+
const variables = {
44+
issueId: bundle.inputData.issue_id,
45+
labelId: bundle.inputData.label_id,
46+
};
47+
48+
const response = await z.request({
49+
url: "https://api.linear.app/graphql",
50+
headers: {
51+
"Content-Type": "application/json",
52+
Accept: "application/json",
53+
authorization: bundle.authData.api_key,
54+
},
55+
body: {
56+
query,
57+
variables,
58+
},
59+
method: "POST",
60+
});
61+
62+
const data = response.json as RemoveIssueLabelResponse;
63+
64+
if (data.errors && data.errors.length) {
65+
const error = data.errors[0];
66+
throw new z.errors.Error(
67+
(error.extensions && error.extensions.userPresentableMessage) || error.message,
68+
"invalid_input",
69+
400
70+
);
71+
}
72+
73+
if (data.data && data.data.issueRemoveLabel && data.data.issueRemoveLabel.success) {
74+
return data.data.issueRemoveLabel.issue;
75+
} else {
76+
throw new z.errors.Error(`Failed to remove label from issue`, "Something went wrong", 400);
77+
}
78+
};
79+
80+
export const removeIssueLabel = {
81+
key: "remove_issue_label",
82+
83+
display: {
84+
hidden: false,
85+
description: "Remove a label from an existing issue in Linear",
86+
label: "Remove Label from Issue",
87+
},
88+
89+
noun: "Label",
90+
91+
operation: {
92+
perform: removeIssueLabelRequest,
93+
94+
inputFields: [
95+
{
96+
required: true,
97+
label: "Issue",
98+
key: "issue_id",
99+
dynamic: "issue.id.identifier",
100+
helpText: "The issue to remove the label from",
101+
},
102+
{
103+
required: true,
104+
label: "Label",
105+
key: "label_id",
106+
dynamic: "label.id.name",
107+
helpText: "The label to remove from the issue",
108+
},
109+
],
110+
111+
sample: {
112+
id: "7b647c45-c528-464d-8634-eecea0f73033",
113+
title: "Sample Issue",
114+
url: "https://linear.app/team-best-team/issue/ENG-123/sample-issue",
115+
identifier: "ENG-123",
116+
},
117+
},
118+
};

0 commit comments

Comments
 (0)