@h-rig/github-provider-plugin 0.0.6-alpha.157 → 0.0.6-alpha.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/identity-env.d.ts +16 -0
- package/dist/src/identity-env.js +239 -0
- package/dist/src/identity.d.ts +17 -0
- package/dist/src/identity.js +134 -0
- package/dist/src/index.d.ts +1 -4
- package/dist/src/index.js +360 -740
- package/dist/src/issue-analysis.d.ts +5 -5
- package/dist/src/issue-analysis.js +6 -6
- package/dist/src/lib.d.ts +16 -0
- package/dist/src/lib.js +485 -0
- package/dist/src/plugin.d.ts +6 -2
- package/dist/src/plugin.js +792 -31
- package/dist/src/profile-ops.d.ts +8 -0
- package/dist/src/profile-ops.js +9 -0
- package/dist/src/service.js +1 -35
- package/dist/src/token-env.d.ts +3 -0
- package/dist/src/token-env.js +26 -0
- package/dist/src/triage-run.js +12 -10
- package/package.json +24 -4
- package/dist/src/auth-store.d.ts +0 -42
- package/dist/src/auth-store.js +0 -226
- package/dist/src/credentials.d.ts +0 -20
- package/dist/src/credentials.js +0 -118
- package/dist/src/github-api.d.ts +0 -107
- package/dist/src/github-api.js +0 -451
- package/dist/src/projects.d.ts +0 -31
- package/dist/src/projects.js +0 -147
package/dist/src/projects.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/github-provider-plugin/src/projects.ts
|
|
3
|
-
function asRecord(value) {
|
|
4
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
5
|
-
}
|
|
6
|
-
function asString(value) {
|
|
7
|
-
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
|
|
8
|
-
}
|
|
9
|
-
function asNumber(value) {
|
|
10
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
11
|
-
}
|
|
12
|
-
async function defaultGraphQLFetch(query, variables, token) {
|
|
13
|
-
const response = await fetch("https://api.github.com/graphql", {
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
"content-type": "application/json",
|
|
17
|
-
authorization: `Bearer ${token}`,
|
|
18
|
-
accept: "application/vnd.github+json"
|
|
19
|
-
},
|
|
20
|
-
body: JSON.stringify({ query, variables })
|
|
21
|
-
});
|
|
22
|
-
const json = await response.json().catch(() => ({}));
|
|
23
|
-
if (!response.ok || json.errors) {
|
|
24
|
-
throw new Error(`GitHub Projects GraphQL request failed: ${JSON.stringify(json.errors ?? { status: response.status })}`);
|
|
25
|
-
}
|
|
26
|
-
return json.data;
|
|
27
|
-
}
|
|
28
|
-
function projectNodesFrom(data) {
|
|
29
|
-
const root = asRecord(data);
|
|
30
|
-
const owner = asRecord(root?.organization) ?? asRecord(root?.user);
|
|
31
|
-
const projects = asRecord(owner?.projectsV2);
|
|
32
|
-
const nodes = projects?.nodes;
|
|
33
|
-
return Array.isArray(nodes) ? nodes : [];
|
|
34
|
-
}
|
|
35
|
-
async function listGitHubProjects(input) {
|
|
36
|
-
const query = `
|
|
37
|
-
query RigListProjects($owner: String!, $first: Int!) {
|
|
38
|
-
organization(login: $owner) { projectsV2(first: $first, orderBy: { field: UPDATED_AT, direction: DESC }) { nodes { id number title url } } }
|
|
39
|
-
user(login: $owner) { projectsV2(first: $first, orderBy: { field: UPDATED_AT, direction: DESC }) { nodes { id number title url } } }
|
|
40
|
-
}
|
|
41
|
-
`;
|
|
42
|
-
const fetchGraphQL = input.fetchGraphQL ?? defaultGraphQLFetch;
|
|
43
|
-
const data = await fetchGraphQL(query, { owner: input.owner, first: input.first ?? 20 }, input.token);
|
|
44
|
-
return projectNodesFrom(data).flatMap((node) => {
|
|
45
|
-
const record = asRecord(node);
|
|
46
|
-
const id = asString(record?.id);
|
|
47
|
-
const number = asNumber(record?.number);
|
|
48
|
-
const title = asString(record?.title);
|
|
49
|
-
if (!id || number === undefined || !title)
|
|
50
|
-
return [];
|
|
51
|
-
return [{ id, number, title, ...asString(record?.url) ? { url: asString(record?.url) } : {} }];
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
async function resolveProjectStatusField(input) {
|
|
55
|
-
const query = `
|
|
56
|
-
query RigProjectStatusField($projectId: ID!) {
|
|
57
|
-
node(id: $projectId) {
|
|
58
|
-
... on ProjectV2 {
|
|
59
|
-
fields(first: 50) {
|
|
60
|
-
nodes {
|
|
61
|
-
... on ProjectV2FieldCommon { id name }
|
|
62
|
-
... on ProjectV2SingleSelectField { id name options { id name } }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
|
-
const fetchGraphQL = input.fetchGraphQL ?? defaultGraphQLFetch;
|
|
70
|
-
const data = await fetchGraphQL(query, { projectId: input.projectId }, input.token);
|
|
71
|
-
const fields = asRecord(asRecord(asRecord(data)?.node)?.fields)?.nodes;
|
|
72
|
-
for (const node of Array.isArray(fields) ? fields : []) {
|
|
73
|
-
const record = asRecord(node);
|
|
74
|
-
if (asString(record?.name)?.toLowerCase() !== "status")
|
|
75
|
-
continue;
|
|
76
|
-
const id = asString(record?.id);
|
|
77
|
-
if (!id)
|
|
78
|
-
continue;
|
|
79
|
-
const options = Array.isArray(record?.options) ? record.options.flatMap((option) => {
|
|
80
|
-
const optionRecord = asRecord(option);
|
|
81
|
-
const optionId = asString(optionRecord?.id);
|
|
82
|
-
const name = asString(optionRecord?.name);
|
|
83
|
-
return optionId && name ? [{ id: optionId, name }] : [];
|
|
84
|
-
}) : [];
|
|
85
|
-
return { id, name: "Status", options };
|
|
86
|
-
}
|
|
87
|
-
throw new Error(`GitHub Project ${input.projectId} does not expose a Status single-select field.`);
|
|
88
|
-
}
|
|
89
|
-
async function ensureIssueProjectItem(input) {
|
|
90
|
-
const query = `
|
|
91
|
-
query RigFindProjectIssueItem($projectId: ID!, $issueNodeId: ID!) {
|
|
92
|
-
node(id: $projectId) {
|
|
93
|
-
... on ProjectV2 {
|
|
94
|
-
items(first: 100) { nodes { id content { ... on Issue { id } } } }
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
`;
|
|
99
|
-
const fetchGraphQL = input.fetchGraphQL ?? defaultGraphQLFetch;
|
|
100
|
-
const data = await fetchGraphQL(query, { projectId: input.projectId, issueNodeId: input.issueNodeId }, input.token);
|
|
101
|
-
const nodes = asRecord(asRecord(asRecord(data)?.node)?.items)?.nodes;
|
|
102
|
-
for (const node of Array.isArray(nodes) ? nodes : []) {
|
|
103
|
-
const record = asRecord(node);
|
|
104
|
-
const content = asRecord(record?.content);
|
|
105
|
-
if (asString(content?.id) === input.issueNodeId) {
|
|
106
|
-
const id2 = asString(record?.id);
|
|
107
|
-
if (id2)
|
|
108
|
-
return { id: id2, created: false };
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const mutation = `
|
|
112
|
-
mutation RigAddIssueToProject($projectId: ID!, $contentId: ID!) {
|
|
113
|
-
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) { item { id } }
|
|
114
|
-
}
|
|
115
|
-
`;
|
|
116
|
-
const created = await fetchGraphQL(mutation, { projectId: input.projectId, contentId: input.issueNodeId }, input.token);
|
|
117
|
-
const addResult = asRecord(asRecord(created)?.addProjectV2ItemById);
|
|
118
|
-
const id = asString(asRecord(addResult?.item)?.id);
|
|
119
|
-
if (!id)
|
|
120
|
-
throw new Error("GitHub Project item creation did not return an item id.");
|
|
121
|
-
return { id, created: true };
|
|
122
|
-
}
|
|
123
|
-
async function updateIssueProjectStatus(input) {
|
|
124
|
-
const mutation = `
|
|
125
|
-
mutation RigUpdateProjectStatus($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
|
|
126
|
-
updateProjectV2ItemFieldValue(input: {
|
|
127
|
-
projectId: $projectId,
|
|
128
|
-
itemId: $itemId,
|
|
129
|
-
fieldId: $fieldId,
|
|
130
|
-
value: { singleSelectOptionId: $optionId }
|
|
131
|
-
}) { projectV2Item { id } }
|
|
132
|
-
}
|
|
133
|
-
`;
|
|
134
|
-
const fetchGraphQL = input.fetchGraphQL ?? defaultGraphQLFetch;
|
|
135
|
-
await fetchGraphQL(mutation, {
|
|
136
|
-
projectId: input.projectId,
|
|
137
|
-
itemId: input.itemId,
|
|
138
|
-
fieldId: input.fieldId,
|
|
139
|
-
optionId: input.optionId
|
|
140
|
-
}, input.token);
|
|
141
|
-
}
|
|
142
|
-
export {
|
|
143
|
-
updateIssueProjectStatus,
|
|
144
|
-
resolveProjectStatusField,
|
|
145
|
-
listGitHubProjects,
|
|
146
|
-
ensureIssueProjectItem
|
|
147
|
-
};
|