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
import { ghIssueFromNodeId } from "https://esm.town/v/augustohp/ghIssueFromNodeId";
export async function ghProjectColumnOfIssue(
nodeId: string,
token: string,
): Promise<string> {
const { Octokit } = await import("npm:@octokit/core");
const octokit = new Octokit({ auth: token });
const issue = await ghIssueFromNodeId(nodeId, token);
const graphqlVariables = {
owner: issue.owner,
repository: issue.repository,
issueNumber: issue.number,
};
const query = `
query($owner:String!, $repository:String!, $issueNumber:Int!, $first:Int=20) {
organization(login: $owner) {
repository(name: $repository) {
issue(number: $issueNumber) {
url,
title,
state,
projectItems(first:$first) {
nodes {
id,
fieldValueByName(name: "Status") {
... on ProjectV2ItemFieldSingleSelectValue {
name
}
}
}
}
}
}
}
}`;
const result = await octokit.graphql(query, graphqlVariables);
const statusColumn = result.organization?.repository?.issue?.projectItems
?.nodes
?.shift();
return statusColumn.fieldValueByName?.name ?? "";
}