Skip to content

Instantly share code, notes, and snippets.

@tskopek
Created May 21, 2020 13:53
Show Gist options
  • Save tskopek/5df570f8fd811dbc43cb82c5df12852c to your computer and use it in GitHub Desktop.
Save tskopek/5df570f8fd811dbc43cb82c5df12852c to your computer and use it in GitHub Desktop.
const url = 'https://api.linear.app/graphql';
const mergedStateId = '1da24699-146f-4a57-bbd6-6d2b92907a0f';
const testingStateId = 'e24aff45-3033-4c31-9a2b-475ecd584545';
const fetch = require('node-fetch');
const linearApiKey = process.env.LINEAR_API_KEY;
const fetchMergedIssues = `
query workflowState($stateId: String!) {
workflowState(id: $stateId) {
issues {
nodes {
id
title
}
}
}
}
`;
const updateIssueState = `
mutation updateIssueState($issueId: String!, $stateId: String!) {
issueUpdate(
id: $issueId,
input: {
stateId: $stateId
}
) {
success
issue {
id
title
number
state {
id
name
}
}
}
}
`;
async function getMergedIssues() {
return new Promise(resolve => {
try {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: linearApiKey,
},
body: JSON.stringify({
query: fetchMergedIssues,
variables: { stateId: mergedStateId },
}),
})
.then(res => res.json())
.then(data => {
const mergedIssueIds = data.data.workflowState.issues.nodes.map(
issue => issue.id
);
resolve(mergedIssueIds);
});
} catch (ex) {
console.log(ex);
resolve([]);
}
});
}
async function updateIssueFromMergedToTesting(issueId) {
try {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: process.env.LINEAR_API_KEY,
},
body: JSON.stringify({
query: updateIssueState,
variables: { issueId, stateId: testingStateId },
}),
})
.then(res => res.json())
.then(data => {
if (data.data.issueUpdate.success) {
console.log(
`Moved LANE-${data.data.issueUpdate.issue.number} from Merged to Testing`
);
}
});
} catch (ex) {
console.log(`Error with ${issueId}`);
console.log(ex);
}
}
async function moveLinearIssuesFromMergedToTesting() {
getMergedIssues().then(mergedIssueIds => {
mergedIssueIds.forEach(issueId => {
updateIssueFromMergedToTesting(issueId);
});
});
}
moveLinearIssuesFromMergedToTesting();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment