Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use addedLabelIds in updateIssue action #86

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linear-zapier",
"version": "4.4.6",
"version": "4.4.7",
"description": "Linear's Zapier integration",
"main": "index.js",
"license": "MIT",
Expand Down
28 changes: 5 additions & 23 deletions src/creates/updateIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,14 @@ interface IssueUpdateResponse {
}[];
}

interface IssueResponse {
data: { issue: { labelIds: string[] } };
}

const updateIssueRequest = async (z: ZObject, bundle: Bundle) => {
if (!bundle.inputData.issueIdToUpdate) {
throw new z.errors.HaltedError("You must specify the ID of the issue to update");
}
const priority = bundle.inputData.priority ? parseInt(bundle.inputData.priority) : undefined;
const estimate = bundle.inputData.estimate ? parseInt(bundle.inputData.estimate) : undefined;
let labelIds: string[] | undefined = undefined;
if (bundle.inputData.labels && bundle.inputData.labels.length > 0) {
// We need to append new labels to the issue's existing label set
const issueQuery = `
query ZapierIssue($id: String!) {
issue(id: $id) {
id
labelIds
}
}
`;
const response = await fetchFromLinear(z, bundle, issueQuery, { id: bundle.inputData.issueIdToUpdate });
const data = response.json as IssueResponse;
const originalLabelIds = data.data.issue.labelIds;
labelIds = uniq([...originalLabelIds, ...bundle.inputData.labels]);
}
const addedLabelIds: string[] | undefined =
bundle.inputData.labels && bundle.inputData.labels.length > 0 ? uniq(bundle.inputData.labels) : undefined;

const variables = omitBy(
{
Expand All @@ -63,7 +45,7 @@ const updateIssueRequest = async (z: ZObject, bundle: Bundle) => {
projectId: bundle.inputData.projectId,
projectMilestoneId: bundle.inputData.projectMilestoneId,
dueDate: bundle.inputData.dueDate,
labelIds,
addedLabelIds: addedLabelIds,
leelasn marked this conversation as resolved.
Show resolved Hide resolved
},
(v) => v === undefined
);
Expand All @@ -82,7 +64,7 @@ const updateIssueRequest = async (z: ZObject, bundle: Bundle) => {
$projectId: String,
$projectMilestoneId: String,
$dueDate: TimelessDate,
$labelIds: [String!]
$addedLabelIds: [String!]
) {
issueUpdate(id: $issueIdToUpdate, input: {
teamId: $teamId,
Expand All @@ -96,7 +78,7 @@ const updateIssueRequest = async (z: ZObject, bundle: Bundle) => {
projectId: $projectId,
projectMilestoneId: $projectMilestoneId,
dueDate: $dueDate,
labelIds: $labelIds
addedLabelIds: $addedLabelIds
}) {
issue {
id
Expand Down
Loading