@h-rig/github-provider-plugin 0.0.6-alpha.156 → 0.0.6-alpha.158
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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IdentityRegistryFilter, resolveRigIdentity, resolveRigIdentityFilter } from "./identity";
|
|
2
|
+
export { resolveRigIdentity, resolveRigIdentityFilter };
|
|
3
|
+
export type { IdentityRegistryFilter };
|
|
4
|
+
declare const PUBLIC_IDENTITY_ENV_KEYS: readonly ["RIG_SELECTED_REPO", "RIG_GITHUB_USER_ID", "RIG_GITHUB_LOGIN", "RIG_GITHUB_NAMESPACE_KEY"];
|
|
5
|
+
export declare function resolveIdentityEnv(workspaceRoot: string): Partial<Record<(typeof PUBLIC_IDENTITY_ENV_KEYS)[number], string>>;
|
|
6
|
+
export declare function applyIdentityEnv(workspaceRoot: string): () => void;
|
|
7
|
+
export declare function identityFilterFromEnv(): IdentityRegistryFilter;
|
|
8
|
+
/**
|
|
9
|
+
* Credential env keys that must be STRIPPED from a spawned run-host child's
|
|
10
|
+
* environment. The operator's session/admin GitHub tokens must not leak into the
|
|
11
|
+
* detached run worker, which resolves its OWN scoped token from the run identity
|
|
12
|
+
* (`github-auth.json` via `RIG_GITHUB_AUTH_STATE_FILE`).
|
|
13
|
+
*/
|
|
14
|
+
export declare const RUN_CHILD_STRIPPED_CREDENTIAL_ENV_KEYS: readonly ["RIG_GITHUB_TOKEN", "RIG_GITHUB_SELECTED_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"];
|
|
15
|
+
/** Return a copy of `env` (default process.env) with run-scoped credential tokens removed. */
|
|
16
|
+
export declare function stripRunChildCredentialEnv(env?: Record<string, string | undefined>): Record<string, string | undefined>;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/github-provider-plugin/src/identity-env.ts
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/github-provider-plugin/src/identity.ts
|
|
7
|
+
import {
|
|
8
|
+
RIG_WORKFLOW_STARTED
|
|
9
|
+
} from "@rig/contracts";
|
|
10
|
+
function stringField(value) {
|
|
11
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
12
|
+
}
|
|
13
|
+
function numericStringField(value) {
|
|
14
|
+
return typeof value === "number" && Number.isInteger(value) ? String(value) : stringField(value);
|
|
15
|
+
}
|
|
16
|
+
function asRecord(value) {
|
|
17
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
18
|
+
}
|
|
19
|
+
function customEntries(entries) {
|
|
20
|
+
const customs = [];
|
|
21
|
+
for (const entry of entries) {
|
|
22
|
+
if (entry.type === "custom")
|
|
23
|
+
customs.push(entry);
|
|
24
|
+
}
|
|
25
|
+
return customs;
|
|
26
|
+
}
|
|
27
|
+
function candidateFromStartedData(data) {
|
|
28
|
+
const record = asRecord(data);
|
|
29
|
+
if (!record)
|
|
30
|
+
return null;
|
|
31
|
+
const owner = asRecord(record.owner);
|
|
32
|
+
const selectedRepo = stringField(record.selectedRepo);
|
|
33
|
+
const githubUserId = stringField(owner?.githubUserId) ?? numericStringField(record.githubUserId) ?? numericStringField(record.userId);
|
|
34
|
+
const login = stringField(owner?.login) ?? stringField(record.login);
|
|
35
|
+
const namespaceKey = stringField(owner?.namespaceKey) ?? stringField(record.namespaceKey) ?? stringField(record.userNamespaceKey);
|
|
36
|
+
if (!selectedRepo && !githubUserId && !login && !namespaceKey)
|
|
37
|
+
return null;
|
|
38
|
+
return { selectedRepo, githubUserId, login, namespaceKey, source: "workflow-metadata" };
|
|
39
|
+
}
|
|
40
|
+
function workflowIdentityCandidate(entries) {
|
|
41
|
+
const customs = customEntries(entries);
|
|
42
|
+
for (let index = customs.length - 1;index >= 0; index -= 1) {
|
|
43
|
+
const entry = customs[index];
|
|
44
|
+
if (entry?.customType !== RIG_WORKFLOW_STARTED)
|
|
45
|
+
continue;
|
|
46
|
+
const candidate = candidateFromStartedData(entry.data);
|
|
47
|
+
if (candidate)
|
|
48
|
+
return candidate;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function ompGitHubIdentityCandidate(ctx) {
|
|
53
|
+
const account = asRecord(ctx.modelRegistry?.authStorage?.getOAuthAccountIdentity?.("github-copilot", ctx.sessionManager.getSessionId()));
|
|
54
|
+
if (!account)
|
|
55
|
+
return null;
|
|
56
|
+
const githubUserId = stringField(account.accountId);
|
|
57
|
+
const login = stringField(account.login) ?? stringField(account.email);
|
|
58
|
+
if (!githubUserId && !login)
|
|
59
|
+
return null;
|
|
60
|
+
return {
|
|
61
|
+
githubUserId,
|
|
62
|
+
login,
|
|
63
|
+
namespaceKey: githubUserId ? `gh:${githubUserId}` : undefined,
|
|
64
|
+
source: "omp-github-copilot-auth"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function envField(name) {
|
|
68
|
+
return stringField(process.env[name]);
|
|
69
|
+
}
|
|
70
|
+
function envIdentityCandidate() {
|
|
71
|
+
const selectedRepo = envField("RIG_SELECTED_REPO");
|
|
72
|
+
const githubUserId = envField("RIG_GITHUB_USER_ID");
|
|
73
|
+
const login = envField("RIG_GITHUB_LOGIN");
|
|
74
|
+
const namespaceKey = envField("RIG_GITHUB_NAMESPACE_KEY") ?? (githubUserId ? `gh:${githubUserId}` : undefined);
|
|
75
|
+
if (!selectedRepo && !githubUserId && !login && !namespaceKey)
|
|
76
|
+
return null;
|
|
77
|
+
return {
|
|
78
|
+
selectedRepo,
|
|
79
|
+
githubUserId,
|
|
80
|
+
login,
|
|
81
|
+
namespaceKey,
|
|
82
|
+
source: "rig-public-identity-env"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function mergeSource(sources, source) {
|
|
86
|
+
if (source && !sources.includes(source))
|
|
87
|
+
sources.push(source);
|
|
88
|
+
}
|
|
89
|
+
function completeIdentity(candidate, sources) {
|
|
90
|
+
const selectedRepo = stringField(candidate.selectedRepo);
|
|
91
|
+
const githubUserId = stringField(candidate.githubUserId);
|
|
92
|
+
const login = stringField(candidate.login);
|
|
93
|
+
const namespaceKey = stringField(candidate.namespaceKey) ?? (githubUserId ? `gh:${githubUserId}` : undefined);
|
|
94
|
+
if (!selectedRepo || !githubUserId || !login || !namespaceKey)
|
|
95
|
+
return null;
|
|
96
|
+
const uniqueSources = [];
|
|
97
|
+
for (const value of sources) {
|
|
98
|
+
if (!uniqueSources.includes(value))
|
|
99
|
+
uniqueSources.push(value);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
selectedRepo,
|
|
103
|
+
owner: { githubUserId, login, namespaceKey },
|
|
104
|
+
source: uniqueSources.join("+")
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function resolveRigIdentity(ctx) {
|
|
108
|
+
const workflow = workflowIdentityCandidate(ctx.sessionManager.getBranch());
|
|
109
|
+
const omp = ompGitHubIdentityCandidate(ctx);
|
|
110
|
+
const env = envIdentityCandidate();
|
|
111
|
+
const sources = [];
|
|
112
|
+
const selectedRepo = workflow?.selectedRepo ?? env?.selectedRepo;
|
|
113
|
+
const githubUserId = workflow?.githubUserId ?? omp?.githubUserId ?? env?.githubUserId;
|
|
114
|
+
const login = workflow?.login ?? omp?.login ?? env?.login;
|
|
115
|
+
const namespaceKey = workflow?.namespaceKey ?? omp?.namespaceKey ?? env?.namespaceKey;
|
|
116
|
+
if (workflow && (workflow.selectedRepo || workflow.githubUserId || workflow.login || workflow.namespaceKey))
|
|
117
|
+
mergeSource(sources, workflow.source);
|
|
118
|
+
if (omp && (!workflow?.githubUserId || !workflow?.login || !workflow?.namespaceKey))
|
|
119
|
+
mergeSource(sources, omp.source);
|
|
120
|
+
if (env && (!workflow?.selectedRepo && env.selectedRepo || !workflow?.githubUserId && !omp?.githubUserId && env.githubUserId || !workflow?.login && !omp?.login && env.login || !workflow?.namespaceKey && !omp?.namespaceKey && env.namespaceKey))
|
|
121
|
+
mergeSource(sources, env.source);
|
|
122
|
+
return completeIdentity({ selectedRepo, githubUserId, login, namespaceKey, source: sources.join("+") }, sources);
|
|
123
|
+
}
|
|
124
|
+
function resolveRigIdentityFilter(ctx) {
|
|
125
|
+
const identity = resolveRigIdentity(ctx);
|
|
126
|
+
if (!identity)
|
|
127
|
+
return null;
|
|
128
|
+
return {
|
|
129
|
+
cwd: ctx.sessionManager.getCwd(),
|
|
130
|
+
selectedRepo: identity.selectedRepo,
|
|
131
|
+
githubUserId: identity.owner.githubUserId,
|
|
132
|
+
namespaceKey: identity.owner.namespaceKey
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// packages/github-provider-plugin/src/identity-env.ts
|
|
137
|
+
var PUBLIC_IDENTITY_ENV_KEYS = [
|
|
138
|
+
"RIG_SELECTED_REPO",
|
|
139
|
+
"RIG_GITHUB_USER_ID",
|
|
140
|
+
"RIG_GITHUB_LOGIN",
|
|
141
|
+
"RIG_GITHUB_NAMESPACE_KEY"
|
|
142
|
+
];
|
|
143
|
+
var RIG_STATE_ENV_KEYS = [
|
|
144
|
+
"RIG_GITHUB_AUTH_STATE_FILE"
|
|
145
|
+
];
|
|
146
|
+
function stringField2(value) {
|
|
147
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
148
|
+
}
|
|
149
|
+
function githubUserId(value) {
|
|
150
|
+
if (typeof value === "number" && Number.isInteger(value))
|
|
151
|
+
return String(value);
|
|
152
|
+
return stringField2(value);
|
|
153
|
+
}
|
|
154
|
+
function readJsonRecord(path) {
|
|
155
|
+
if (!existsSync(path))
|
|
156
|
+
return null;
|
|
157
|
+
try {
|
|
158
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
159
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function resolveIdentityEnv(workspaceRoot) {
|
|
165
|
+
const stateDir = resolve(workspaceRoot, ".rig", "state");
|
|
166
|
+
const auth = readJsonRecord(resolve(stateDir, "github-auth.json"));
|
|
167
|
+
const connection = readJsonRecord(resolve(stateDir, "connection.json"));
|
|
168
|
+
const projectLink = readJsonRecord(resolve(stateDir, "project-link.json"));
|
|
169
|
+
const values = {};
|
|
170
|
+
const selectedRepo = stringField2(auth?.selectedRepo) ?? stringField2(connection?.project) ?? stringField2(projectLink?.repoSlug);
|
|
171
|
+
const userId = githubUserId(auth?.userId);
|
|
172
|
+
const login = stringField2(auth?.login);
|
|
173
|
+
const namespaceKey = stringField2(auth?.userNamespaceKey);
|
|
174
|
+
if (selectedRepo)
|
|
175
|
+
values.RIG_SELECTED_REPO = selectedRepo;
|
|
176
|
+
if (userId)
|
|
177
|
+
values.RIG_GITHUB_USER_ID = userId;
|
|
178
|
+
if (login)
|
|
179
|
+
values.RIG_GITHUB_LOGIN = login;
|
|
180
|
+
if (namespaceKey)
|
|
181
|
+
values.RIG_GITHUB_NAMESPACE_KEY = namespaceKey;
|
|
182
|
+
return values;
|
|
183
|
+
}
|
|
184
|
+
function applyIdentityEnv(workspaceRoot) {
|
|
185
|
+
const previous = new Map;
|
|
186
|
+
for (const key of [...PUBLIC_IDENTITY_ENV_KEYS, ...RIG_STATE_ENV_KEYS])
|
|
187
|
+
previous.set(key, process.env[key]);
|
|
188
|
+
const stateDir = resolve(workspaceRoot, ".rig", "state");
|
|
189
|
+
const auth = readJsonRecord(resolve(stateDir, "github-auth.json"));
|
|
190
|
+
const connection = readJsonRecord(resolve(stateDir, "connection.json"));
|
|
191
|
+
const projectLink = readJsonRecord(resolve(stateDir, "project-link.json"));
|
|
192
|
+
const values = { ...resolveIdentityEnv(workspaceRoot) };
|
|
193
|
+
values.RIG_GITHUB_AUTH_STATE_FILE = resolve(stateDir, "github-auth.json");
|
|
194
|
+
const hasLocalIdentityState = Boolean(auth || connection || projectLink);
|
|
195
|
+
for (const key of [...PUBLIC_IDENTITY_ENV_KEYS, ...RIG_STATE_ENV_KEYS]) {
|
|
196
|
+
const value = values[key];
|
|
197
|
+
if (value)
|
|
198
|
+
process.env[key] = value;
|
|
199
|
+
else if (hasLocalIdentityState)
|
|
200
|
+
delete process.env[key];
|
|
201
|
+
}
|
|
202
|
+
return () => {
|
|
203
|
+
for (const key of [...PUBLIC_IDENTITY_ENV_KEYS, ...RIG_STATE_ENV_KEYS]) {
|
|
204
|
+
const value = previous.get(key);
|
|
205
|
+
if (value === undefined)
|
|
206
|
+
delete process.env[key];
|
|
207
|
+
else
|
|
208
|
+
process.env[key] = value;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function identityFilterFromEnv() {
|
|
213
|
+
return {
|
|
214
|
+
...process.env.RIG_SELECTED_REPO ? { selectedRepo: process.env.RIG_SELECTED_REPO } : {},
|
|
215
|
+
...process.env.RIG_GITHUB_USER_ID ? { githubUserId: process.env.RIG_GITHUB_USER_ID } : {},
|
|
216
|
+
...process.env.RIG_GITHUB_NAMESPACE_KEY ? { namespaceKey: process.env.RIG_GITHUB_NAMESPACE_KEY } : {}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
var RUN_CHILD_STRIPPED_CREDENTIAL_ENV_KEYS = [
|
|
220
|
+
"RIG_GITHUB_TOKEN",
|
|
221
|
+
"RIG_GITHUB_SELECTED_TOKEN",
|
|
222
|
+
"GH_TOKEN",
|
|
223
|
+
"GITHUB_TOKEN"
|
|
224
|
+
];
|
|
225
|
+
function stripRunChildCredentialEnv(env = process.env) {
|
|
226
|
+
const next = { ...env };
|
|
227
|
+
for (const key of RUN_CHILD_STRIPPED_CREDENTIAL_ENV_KEYS)
|
|
228
|
+
delete next[key];
|
|
229
|
+
return next;
|
|
230
|
+
}
|
|
231
|
+
export {
|
|
232
|
+
stripRunChildCredentialEnv,
|
|
233
|
+
resolveRigIdentityFilter,
|
|
234
|
+
resolveRigIdentity,
|
|
235
|
+
resolveIdentityEnv,
|
|
236
|
+
identityFilterFromEnv,
|
|
237
|
+
applyIdentityEnv,
|
|
238
|
+
RUN_CHILD_STRIPPED_CREDENTIAL_ENV_KEYS
|
|
239
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* identity.ts — GitHub-owned Rig run-identity resolver.
|
|
3
|
+
*
|
|
4
|
+
* Derives `{ selectedRepo, owner }` from the OMP workflow/session projection,
|
|
5
|
+
* GitHub Copilot auth identity, and public Rig identity env. The structural
|
|
6
|
+
* vocabulary lives in `@rig/contracts`; this package owns the provider behavior
|
|
7
|
+
* and exposes it through the RUN_IDENTITY_ENV capability for sibling plugins.
|
|
8
|
+
*
|
|
9
|
+
* The discovery-filter return type is declared structurally in the contract (an
|
|
10
|
+
* exact structural mirror of `CollabRegistryFilter` from `@rig/relay-registry`)
|
|
11
|
+
* so provider consumers can pass it to registry/discovery seams without adding a
|
|
12
|
+
* transport package dependency.
|
|
13
|
+
*/
|
|
14
|
+
import { type RigIdentityContext, type RigResolvedIdentity, type IdentityRegistryFilter } from "@rig/contracts";
|
|
15
|
+
export type { RigIdentity, RigIdentityContext, RigResolvedIdentity, IdentityRegistryFilter } from "@rig/contracts";
|
|
16
|
+
export declare function resolveRigIdentity(ctx: RigIdentityContext): RigResolvedIdentity | null;
|
|
17
|
+
export declare function resolveRigIdentityFilter(ctx: RigIdentityContext): IdentityRegistryFilter | null;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/github-provider-plugin/src/identity.ts
|
|
3
|
+
import {
|
|
4
|
+
RIG_WORKFLOW_STARTED
|
|
5
|
+
} from "@rig/contracts";
|
|
6
|
+
function stringField(value) {
|
|
7
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
8
|
+
}
|
|
9
|
+
function numericStringField(value) {
|
|
10
|
+
return typeof value === "number" && Number.isInteger(value) ? String(value) : stringField(value);
|
|
11
|
+
}
|
|
12
|
+
function asRecord(value) {
|
|
13
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
14
|
+
}
|
|
15
|
+
function customEntries(entries) {
|
|
16
|
+
const customs = [];
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (entry.type === "custom")
|
|
19
|
+
customs.push(entry);
|
|
20
|
+
}
|
|
21
|
+
return customs;
|
|
22
|
+
}
|
|
23
|
+
function candidateFromStartedData(data) {
|
|
24
|
+
const record = asRecord(data);
|
|
25
|
+
if (!record)
|
|
26
|
+
return null;
|
|
27
|
+
const owner = asRecord(record.owner);
|
|
28
|
+
const selectedRepo = stringField(record.selectedRepo);
|
|
29
|
+
const githubUserId = stringField(owner?.githubUserId) ?? numericStringField(record.githubUserId) ?? numericStringField(record.userId);
|
|
30
|
+
const login = stringField(owner?.login) ?? stringField(record.login);
|
|
31
|
+
const namespaceKey = stringField(owner?.namespaceKey) ?? stringField(record.namespaceKey) ?? stringField(record.userNamespaceKey);
|
|
32
|
+
if (!selectedRepo && !githubUserId && !login && !namespaceKey)
|
|
33
|
+
return null;
|
|
34
|
+
return { selectedRepo, githubUserId, login, namespaceKey, source: "workflow-metadata" };
|
|
35
|
+
}
|
|
36
|
+
function workflowIdentityCandidate(entries) {
|
|
37
|
+
const customs = customEntries(entries);
|
|
38
|
+
for (let index = customs.length - 1;index >= 0; index -= 1) {
|
|
39
|
+
const entry = customs[index];
|
|
40
|
+
if (entry?.customType !== RIG_WORKFLOW_STARTED)
|
|
41
|
+
continue;
|
|
42
|
+
const candidate = candidateFromStartedData(entry.data);
|
|
43
|
+
if (candidate)
|
|
44
|
+
return candidate;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function ompGitHubIdentityCandidate(ctx) {
|
|
49
|
+
const account = asRecord(ctx.modelRegistry?.authStorage?.getOAuthAccountIdentity?.("github-copilot", ctx.sessionManager.getSessionId()));
|
|
50
|
+
if (!account)
|
|
51
|
+
return null;
|
|
52
|
+
const githubUserId = stringField(account.accountId);
|
|
53
|
+
const login = stringField(account.login) ?? stringField(account.email);
|
|
54
|
+
if (!githubUserId && !login)
|
|
55
|
+
return null;
|
|
56
|
+
return {
|
|
57
|
+
githubUserId,
|
|
58
|
+
login,
|
|
59
|
+
namespaceKey: githubUserId ? `gh:${githubUserId}` : undefined,
|
|
60
|
+
source: "omp-github-copilot-auth"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function envField(name) {
|
|
64
|
+
return stringField(process.env[name]);
|
|
65
|
+
}
|
|
66
|
+
function envIdentityCandidate() {
|
|
67
|
+
const selectedRepo = envField("RIG_SELECTED_REPO");
|
|
68
|
+
const githubUserId = envField("RIG_GITHUB_USER_ID");
|
|
69
|
+
const login = envField("RIG_GITHUB_LOGIN");
|
|
70
|
+
const namespaceKey = envField("RIG_GITHUB_NAMESPACE_KEY") ?? (githubUserId ? `gh:${githubUserId}` : undefined);
|
|
71
|
+
if (!selectedRepo && !githubUserId && !login && !namespaceKey)
|
|
72
|
+
return null;
|
|
73
|
+
return {
|
|
74
|
+
selectedRepo,
|
|
75
|
+
githubUserId,
|
|
76
|
+
login,
|
|
77
|
+
namespaceKey,
|
|
78
|
+
source: "rig-public-identity-env"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function mergeSource(sources, source) {
|
|
82
|
+
if (source && !sources.includes(source))
|
|
83
|
+
sources.push(source);
|
|
84
|
+
}
|
|
85
|
+
function completeIdentity(candidate, sources) {
|
|
86
|
+
const selectedRepo = stringField(candidate.selectedRepo);
|
|
87
|
+
const githubUserId = stringField(candidate.githubUserId);
|
|
88
|
+
const login = stringField(candidate.login);
|
|
89
|
+
const namespaceKey = stringField(candidate.namespaceKey) ?? (githubUserId ? `gh:${githubUserId}` : undefined);
|
|
90
|
+
if (!selectedRepo || !githubUserId || !login || !namespaceKey)
|
|
91
|
+
return null;
|
|
92
|
+
const uniqueSources = [];
|
|
93
|
+
for (const value of sources) {
|
|
94
|
+
if (!uniqueSources.includes(value))
|
|
95
|
+
uniqueSources.push(value);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
selectedRepo,
|
|
99
|
+
owner: { githubUserId, login, namespaceKey },
|
|
100
|
+
source: uniqueSources.join("+")
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function resolveRigIdentity(ctx) {
|
|
104
|
+
const workflow = workflowIdentityCandidate(ctx.sessionManager.getBranch());
|
|
105
|
+
const omp = ompGitHubIdentityCandidate(ctx);
|
|
106
|
+
const env = envIdentityCandidate();
|
|
107
|
+
const sources = [];
|
|
108
|
+
const selectedRepo = workflow?.selectedRepo ?? env?.selectedRepo;
|
|
109
|
+
const githubUserId = workflow?.githubUserId ?? omp?.githubUserId ?? env?.githubUserId;
|
|
110
|
+
const login = workflow?.login ?? omp?.login ?? env?.login;
|
|
111
|
+
const namespaceKey = workflow?.namespaceKey ?? omp?.namespaceKey ?? env?.namespaceKey;
|
|
112
|
+
if (workflow && (workflow.selectedRepo || workflow.githubUserId || workflow.login || workflow.namespaceKey))
|
|
113
|
+
mergeSource(sources, workflow.source);
|
|
114
|
+
if (omp && (!workflow?.githubUserId || !workflow?.login || !workflow?.namespaceKey))
|
|
115
|
+
mergeSource(sources, omp.source);
|
|
116
|
+
if (env && (!workflow?.selectedRepo && env.selectedRepo || !workflow?.githubUserId && !omp?.githubUserId && env.githubUserId || !workflow?.login && !omp?.login && env.login || !workflow?.namespaceKey && !omp?.namespaceKey && env.namespaceKey))
|
|
117
|
+
mergeSource(sources, env.source);
|
|
118
|
+
return completeIdentity({ selectedRepo, githubUserId, login, namespaceKey, source: sources.join("+") }, sources);
|
|
119
|
+
}
|
|
120
|
+
function resolveRigIdentityFilter(ctx) {
|
|
121
|
+
const identity = resolveRigIdentity(ctx);
|
|
122
|
+
if (!identity)
|
|
123
|
+
return null;
|
|
124
|
+
return {
|
|
125
|
+
cwd: ctx.sessionManager.getCwd(),
|
|
126
|
+
selectedRepo: identity.selectedRepo,
|
|
127
|
+
githubUserId: identity.owner.githubUserId,
|
|
128
|
+
namespaceKey: identity.owner.namespaceKey
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
resolveRigIdentityFilter,
|
|
133
|
+
resolveRigIdentity
|
|
134
|
+
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./credentials";
|
|
3
|
-
export * from "./projects";
|
|
4
|
-
export * from "./github-api";
|
|
1
|
+
export * from "@rig/github-lib";
|
|
5
2
|
export * from "./issue-analysis";
|
|
6
3
|
export * from "./triage-run";
|
|
7
4
|
export { GITHUB_PROVIDER_PLUGIN_NAME, githubProviderPlugin, createGitHubProviderPlugin, } from "./plugin";
|