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 ?? "";
}