@theholocron/holocron-plugin-github 5.0.0-alpha.502 → 5.0.0-alpha.503
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/index.d.mts +9 -0
- package/dist/index.mjs +612 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -30,6 +30,11 @@ export declare const resolveDeployToken: import("@theholocron/cli").FeatureResol
|
|
|
30
30
|
export declare const resolveUserSyncToken: import("@theholocron/cli").FeatureResolver;
|
|
31
31
|
/** Resolves the org-level token (`HOLOCRON_ORG_TOKEN`, keyring key `github.org`). */
|
|
32
32
|
export declare const resolveOrgToken: import("@theholocron/cli").FeatureResolver;
|
|
33
|
+
/** The area declaration the plugin is handed from `repo.labels`. */
|
|
34
|
+
interface AreaConfig {
|
|
35
|
+
areas?: Record<string, string[]>;
|
|
36
|
+
scopes?: Record<string, string>;
|
|
37
|
+
}
|
|
33
38
|
interface CiOptions {
|
|
34
39
|
repo: string;
|
|
35
40
|
}
|
|
@@ -333,6 +338,7 @@ export declare class GitHubSource implements Source {
|
|
|
333
338
|
removeWorkflowFile(name: string): Promise<void>;
|
|
334
339
|
writeRepoFile(path: string, contents: string): Promise<void>;
|
|
335
340
|
syncLabels(canonical: ReadonlyArray<LabelDef>, stale: ReadonlyArray<string>): Promise<string>;
|
|
341
|
+
ensureLabels(labels: ReadonlyArray<LabelDef>): Promise<string>;
|
|
336
342
|
syncProperties(values: Record<string, string | string[]>): Promise<string>;
|
|
337
343
|
getOrgPropertyValues(name: string): Promise<string[] | undefined>;
|
|
338
344
|
addOrgPropertyValues(name: string, values: string[]): Promise<string[]>;
|
|
@@ -430,6 +436,8 @@ export interface GitHubPluginOptions extends ResolveTokenInput {
|
|
|
430
436
|
/** Label that marks an issue as in review. */
|
|
431
437
|
inReview: string;
|
|
432
438
|
};
|
|
439
|
+
/** `repo.labels` (the area map), handed in by the loader for the `issue-types` probe. */
|
|
440
|
+
areaLabels?: AreaConfig;
|
|
433
441
|
/** Override base URL for tests. Defaults to https://api.github.com. */
|
|
434
442
|
baseUrl?: string;
|
|
435
443
|
/** Override `fetch` for tests. Defaults to global `fetch`. */
|
|
@@ -463,6 +471,7 @@ export declare function createPlugin(options: GitHubPluginOptions): {
|
|
|
463
471
|
name: string;
|
|
464
472
|
probes: {
|
|
465
473
|
token: import("@theholocron/cli").Probe;
|
|
474
|
+
"issue-types": import("@theholocron/cli").Probe;
|
|
466
475
|
connection: import("@theholocron/cli").Probe;
|
|
467
476
|
};
|
|
468
477
|
capabilities: {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { AuthError, MissingTokenError, ProviderApiError, connectionProbe, createFeatureResolver, pickByCreation, readKeysLimited, reportProgress, tokenExpectations } from "@theholocron/cli";
|
|
2
|
+
import { AuthError, MissingTokenError, ProviderApiError, areaLabelsForFiles, areaLabelsForTitle, connectionProbe, createFeatureResolver, pickByCreation, readKeysLimited, reportProgress, tokenExpectations } from "@theholocron/cli";
|
|
3
3
|
import { createGitHubClient, createGitHubClient as createGitHubClient$1 } from "@theholocron/github-client";
|
|
4
4
|
import { mkdir, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
@@ -2007,6 +2007,25 @@ async function syncLabels(client, repo, canonical, stale) {
|
|
|
2007
2007
|
}
|
|
2008
2008
|
return `${created} created, ${updated} updated, ${deleted} deleted`;
|
|
2009
2009
|
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Make the labels a repo lacks and change nothing else: an existing label (found without regard to case) keeps its
|
|
2012
|
+
* colour and description, and nothing is deleted. Used for the `area:<name>` family, which is not in the canonical set.
|
|
2013
|
+
*/
|
|
2014
|
+
async function ensureLabels(client, repo, labels) {
|
|
2015
|
+
const existing = await client.labels.listLabels(repo);
|
|
2016
|
+
const have = new Set(existing.map((l) => l.name.toLowerCase()));
|
|
2017
|
+
let created = 0;
|
|
2018
|
+
for (const label of labels) {
|
|
2019
|
+
if (have.has(label.name.toLowerCase())) continue;
|
|
2020
|
+
await client.labels.createLabel(repo, {
|
|
2021
|
+
name: label.name,
|
|
2022
|
+
color: label.color,
|
|
2023
|
+
description: label.description
|
|
2024
|
+
});
|
|
2025
|
+
created++;
|
|
2026
|
+
}
|
|
2027
|
+
return `${created} created, ${labels.length - created} already there`;
|
|
2028
|
+
}
|
|
2010
2029
|
// src/capabilities/property-fix-hints.ts
|
|
2011
2030
|
/** GitHub's wording when a custom property value is not one the organization's definition allows. */
|
|
2012
2031
|
const NOT_ALLOWED = /Value '([^']+)' is not allowed for property '([^']+)'/g;
|
|
@@ -2638,6 +2657,9 @@ var GitHubSource = class {
|
|
|
2638
2657
|
async syncLabels(canonical, stale) {
|
|
2639
2658
|
return syncLabels(this.client, this.repo, canonical, stale);
|
|
2640
2659
|
}
|
|
2660
|
+
async ensureLabels(labels) {
|
|
2661
|
+
return ensureLabels(this.client, this.repo, labels);
|
|
2662
|
+
}
|
|
2641
2663
|
async syncProperties(values) {
|
|
2642
2664
|
return syncProperties(this.client, this.repo, values, this.orgClient ?? this.client);
|
|
2643
2665
|
}
|
|
@@ -2800,6 +2822,591 @@ async function ensureDir(path) {
|
|
|
2800
2822
|
throw err;
|
|
2801
2823
|
}
|
|
2802
2824
|
}
|
|
2825
|
+
// src/probes/issue-types/github-api.ts
|
|
2826
|
+
const PAGE = 100;
|
|
2827
|
+
const PROJECTS_OF = `query($ids: [ID!]!) { nodes(ids: $ids) { ... on Issue { id projectItems(first: 20) { nodes { project { id } } } } } }`;
|
|
2828
|
+
const ADD_ITEM = `mutation($project: ID!, $content: ID!) { addProjectV2ItemById(input: { projectId: $project, contentId: $content }) { item { id } } }`;
|
|
2829
|
+
function toItem(issue) {
|
|
2830
|
+
return {
|
|
2831
|
+
number: issue.number,
|
|
2832
|
+
title: issue.title,
|
|
2833
|
+
state: issue.state,
|
|
2834
|
+
labels: issue.labels.map((l) => l.name),
|
|
2835
|
+
type: issue.type?.name ?? null,
|
|
2836
|
+
milestone: issue.milestone ?? null,
|
|
2837
|
+
nodeId: issue.node_id ?? "",
|
|
2838
|
+
isPullRequest: issue.pull_request !== void 0,
|
|
2839
|
+
createdAt: issue.created_at ?? ""
|
|
2840
|
+
};
|
|
2841
|
+
}
|
|
2842
|
+
/**
|
|
2843
|
+
* The backfill's reads and writes over the GitHub client. `client` reads and writes issues (the `github.issues` token);
|
|
2844
|
+
* `orgClient` reads and writes the organization's projects (the `github.org` token). Each method is the one call, or the
|
|
2845
|
+
* fixed few, its name says, so the probe's logic is tested against a fake of {@link BackfillApi} and this stays thin.
|
|
2846
|
+
*/
|
|
2847
|
+
function createBackfillApi(client, orgClient, repo) {
|
|
2848
|
+
const org = repo.split("/")[0];
|
|
2849
|
+
const projects = new GitHubProjects(orgClient.graphql, { repo });
|
|
2850
|
+
let fieldList;
|
|
2851
|
+
const fields = async () => fieldList ??= client.issueFields.list(org);
|
|
2852
|
+
return {
|
|
2853
|
+
async list(page) {
|
|
2854
|
+
return (await client.issues.listIssues(repo, {
|
|
2855
|
+
state: "all",
|
|
2856
|
+
sort: "created",
|
|
2857
|
+
direction: "asc",
|
|
2858
|
+
per_page: PAGE,
|
|
2859
|
+
page
|
|
2860
|
+
})).map(toItem);
|
|
2861
|
+
},
|
|
2862
|
+
async get(number) {
|
|
2863
|
+
return toItem(await client.issues.getIssue(repo, number));
|
|
2864
|
+
},
|
|
2865
|
+
async parent(number) {
|
|
2866
|
+
const parent = await client.issues.getParent(repo, number);
|
|
2867
|
+
return parent ? {
|
|
2868
|
+
number: parent.number,
|
|
2869
|
+
milestone: parent.milestone?.number ?? null
|
|
2870
|
+
} : null;
|
|
2871
|
+
},
|
|
2872
|
+
async labelNames() {
|
|
2873
|
+
return new Set((await client.labels.listLabels(repo)).map((l) => l.name.toLowerCase()));
|
|
2874
|
+
},
|
|
2875
|
+
async milestoneNumber(title) {
|
|
2876
|
+
return (await client.issues.listMilestones(repo, { state: "all" })).find((m) => m.title.toLowerCase() === title.toLowerCase())?.number;
|
|
2877
|
+
},
|
|
2878
|
+
async projectId(title) {
|
|
2879
|
+
return (await projects.find(org, title))?.id;
|
|
2880
|
+
},
|
|
2881
|
+
async projectsOf(nodeIds) {
|
|
2882
|
+
const data = await orgClient.graphql.query(PROJECTS_OF, { ids: nodeIds });
|
|
2883
|
+
const out = /* @__PURE__ */ new Map();
|
|
2884
|
+
for (const node of data.nodes) if (node?.id) out.set(node.id, (node.projectItems?.nodes ?? []).map((i) => i.project.id));
|
|
2885
|
+
return out;
|
|
2886
|
+
},
|
|
2887
|
+
async fieldNames() {
|
|
2888
|
+
try {
|
|
2889
|
+
return new Set((await fields()).map((f) => f.name.toLowerCase()));
|
|
2890
|
+
} catch (err) {
|
|
2891
|
+
const why = fieldRefusal(err);
|
|
2892
|
+
if (why === void 0) throw err;
|
|
2893
|
+
return why;
|
|
2894
|
+
}
|
|
2895
|
+
},
|
|
2896
|
+
async fieldValues(number) {
|
|
2897
|
+
const byId = new Map((await fields()).map((f) => [f.id, f.name.toLowerCase()]));
|
|
2898
|
+
const values = await client.issueFields.values(repo, number);
|
|
2899
|
+
return new Set(values.map((v) => v.issue_field_name?.toLowerCase() ?? byId.get(v.issue_field_id) ?? ""));
|
|
2900
|
+
},
|
|
2901
|
+
async files(number) {
|
|
2902
|
+
return (await client.pulls.listFiles(repo, number)).map((f) => f.filename);
|
|
2903
|
+
},
|
|
2904
|
+
async setType(number, type) {
|
|
2905
|
+
await client.issues.updateIssue(repo, number, { type });
|
|
2906
|
+
},
|
|
2907
|
+
async addLabels(number, labels) {
|
|
2908
|
+
await client.issues.addLabels(repo, number, labels);
|
|
2909
|
+
},
|
|
2910
|
+
async setMilestone(number, milestone) {
|
|
2911
|
+
await client.issues.updateIssue(repo, number, { milestone });
|
|
2912
|
+
},
|
|
2913
|
+
async addToProject(projectId, nodeId) {
|
|
2914
|
+
await orgClient.graphql.query(ADD_ITEM, {
|
|
2915
|
+
project: projectId,
|
|
2916
|
+
content: nodeId
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
// src/probes/issue-types/gather.ts
|
|
2922
|
+
/** Whether a day (`YYYY-MM-DD`) is before the start of the window. */
|
|
2923
|
+
const before = (item, since) => since !== void 0 && item.createdAt.slice(0, 10) < since;
|
|
2924
|
+
/** The issues named by `--issues`, past the cursor, at most `limit` of them. */
|
|
2925
|
+
async function named(api, options, isRateLimited) {
|
|
2926
|
+
const numbers = [...new Set(options.issues)].sort((a, b) => a - b).filter((n) => n > options.after);
|
|
2927
|
+
const out = {
|
|
2928
|
+
items: [],
|
|
2929
|
+
more: numbers.length > options.limit,
|
|
2930
|
+
rateLimited: false,
|
|
2931
|
+
pullRequestsSkipped: 0
|
|
2932
|
+
};
|
|
2933
|
+
for (const number of numbers.slice(0, options.limit)) try {
|
|
2934
|
+
const item = await api.get(number);
|
|
2935
|
+
if (item.isPullRequest && !options.pullRequests) out.pullRequestsSkipped++;
|
|
2936
|
+
else out.items.push(item);
|
|
2937
|
+
} catch (err) {
|
|
2938
|
+
if (!isRateLimited(err)) throw err;
|
|
2939
|
+
return {
|
|
2940
|
+
...out,
|
|
2941
|
+
more: true,
|
|
2942
|
+
rateLimited: true
|
|
2943
|
+
};
|
|
2944
|
+
}
|
|
2945
|
+
return out;
|
|
2946
|
+
}
|
|
2947
|
+
/**
|
|
2948
|
+
* The items one run looks at: with `--issues` those numbers, otherwise every issue of the repository oldest first, a
|
|
2949
|
+
* page at a time, past the `--after` cursor and on or after `--since`, until `--limit` are kept. Issue numbers rise with
|
|
2950
|
+
* creation, so the last number read is a cursor the next run can resume from. A rate limit ends the read with what it has.
|
|
2951
|
+
*/
|
|
2952
|
+
async function gather(api, options, isRateLimited) {
|
|
2953
|
+
if (options.issues) return named(api, options, isRateLimited);
|
|
2954
|
+
const out = {
|
|
2955
|
+
items: [],
|
|
2956
|
+
more: false,
|
|
2957
|
+
rateLimited: false,
|
|
2958
|
+
pullRequestsSkipped: 0
|
|
2959
|
+
};
|
|
2960
|
+
try {
|
|
2961
|
+
for (let page = 1;; page++) {
|
|
2962
|
+
const batch = await api.list(page);
|
|
2963
|
+
if (batch.length === 0) return out;
|
|
2964
|
+
for (const item of batch) {
|
|
2965
|
+
if (item.number <= options.after || before(item, options.since)) continue;
|
|
2966
|
+
if (item.isPullRequest && !options.pullRequests) {
|
|
2967
|
+
out.pullRequestsSkipped++;
|
|
2968
|
+
continue;
|
|
2969
|
+
}
|
|
2970
|
+
if (out.items.length >= options.limit) return {
|
|
2971
|
+
...out,
|
|
2972
|
+
more: true
|
|
2973
|
+
};
|
|
2974
|
+
out.items.push(item);
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
} catch (err) {
|
|
2978
|
+
if (!isRateLimited(err)) throw err;
|
|
2979
|
+
return {
|
|
2980
|
+
...out,
|
|
2981
|
+
more: true,
|
|
2982
|
+
rateLimited: true
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
// src/probes/issue-types/plan-type.ts
|
|
2987
|
+
/** The kind labels and the Type each one means (spec `tech-github-area-labels`, decision 3). */
|
|
2988
|
+
const KIND_TYPES = {
|
|
2989
|
+
bug: "Bug",
|
|
2990
|
+
enhancement: "Feature",
|
|
2991
|
+
chore: "Task"
|
|
2992
|
+
};
|
|
2993
|
+
/**
|
|
2994
|
+
* The Type an issue gets from its kind labels. One that has a Type keeps it, whatever its labels say; one with exactly
|
|
2995
|
+
* one of `bug`, `enhancement` and `chore` gets that label's Type; one with two or more is `ambiguous` and left for a
|
|
2996
|
+
* person (the spec's rule: the probe never picks between two kinds); one with none has no source.
|
|
2997
|
+
*/
|
|
2998
|
+
function planType(item) {
|
|
2999
|
+
if (item.type) return { skip: "typed" };
|
|
3000
|
+
const kinds = [...new Set(item.labels.map((l) => l.toLowerCase()).filter((l) => l in KIND_TYPES))];
|
|
3001
|
+
if (kinds.length === 0) return { skip: "no-kind-label" };
|
|
3002
|
+
if (kinds.length > 1) return {
|
|
3003
|
+
skip: "ambiguous",
|
|
3004
|
+
labels: kinds
|
|
3005
|
+
};
|
|
3006
|
+
return { set: KIND_TYPES[kinds[0]] };
|
|
3007
|
+
}
|
|
3008
|
+
// src/probes/issue-types/report.ts
|
|
3009
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
3010
|
+
const GROUPS = [
|
|
3011
|
+
["project", "a project"],
|
|
3012
|
+
["milestone", "a milestone"],
|
|
3013
|
+
["priority", "a Priority"],
|
|
3014
|
+
["effort", "an Effort"]
|
|
3015
|
+
];
|
|
3016
|
+
/** The command the maintainer runs to continue, from the cursor. */
|
|
3017
|
+
function resumeCommand(options, cursor) {
|
|
3018
|
+
const flags = ["--after", String(cursor)];
|
|
3019
|
+
if (options.issues) flags.push("--issues", options.issues.join(","));
|
|
3020
|
+
if (options.since) flags.push("--since", options.since);
|
|
3021
|
+
flags.push("--limit", String(options.limit));
|
|
3022
|
+
if (options.milestone) flags.push("--milestone", options.milestone);
|
|
3023
|
+
if (options.project) flags.push("--project", options.project);
|
|
3024
|
+
if (options.pullRequests) flags.push("--pull-requests");
|
|
3025
|
+
return `holocron probe github issue-types -- ${flags.join(" ")}`;
|
|
3026
|
+
}
|
|
3027
|
+
/** Prints the counts, what was left for a person, the lists of what is still missing and how to go on. */
|
|
3028
|
+
function reportBackfill(ctx, input) {
|
|
3029
|
+
const { tally, options, dryRun, more, rateLimited, fields } = input;
|
|
3030
|
+
const verb = dryRun ? "would be set" : "set";
|
|
3031
|
+
ctx.say({
|
|
3032
|
+
status: "heading",
|
|
3033
|
+
label: "Backfill"
|
|
3034
|
+
});
|
|
3035
|
+
ctx.say({
|
|
3036
|
+
status: "info",
|
|
3037
|
+
label: "read",
|
|
3038
|
+
detail: `${plural(tally.examined, "item")} finished` + (tally.pullRequestsSkipped > 0 ? `, ${plural(tally.pullRequestsSkipped, "pull request")} passed over` : "") + (tally.failed > 0 ? `, ${plural(tally.failed, "failure")}` : "")
|
|
3039
|
+
});
|
|
3040
|
+
const types = Object.entries(tally.typeSet).map(([name, n]) => `${name} ${n}`).join(", ");
|
|
3041
|
+
ctx.say({
|
|
3042
|
+
status: "info",
|
|
3043
|
+
label: "Type",
|
|
3044
|
+
detail: `${types || "none"} ${verb}; ${tally.typed} already typed, ${tally.noKind} with no kind label, ${tally.ambiguous.length} with two kind labels`
|
|
3045
|
+
});
|
|
3046
|
+
for (const a of tally.ambiguous) ctx.say({
|
|
3047
|
+
status: "info",
|
|
3048
|
+
label: `#${a.number}`,
|
|
3049
|
+
detail: `has ${a.labels.join(" and ")}: left for a person to choose`
|
|
3050
|
+
});
|
|
3051
|
+
ctx.say({
|
|
3052
|
+
status: "info",
|
|
3053
|
+
label: "area labels",
|
|
3054
|
+
detail: `added to ${plural(tally.areaLabelsAdded, "item")}`
|
|
3055
|
+
});
|
|
3056
|
+
for (const label of tally.missingAreaLabels) ctx.say({
|
|
3057
|
+
status: "info",
|
|
3058
|
+
label,
|
|
3059
|
+
detail: "wanted but the repository has no such label: run `holocron setup` first"
|
|
3060
|
+
});
|
|
3061
|
+
ctx.say({
|
|
3062
|
+
status: "info",
|
|
3063
|
+
label: "milestone",
|
|
3064
|
+
detail: `${verb} on ${tally.milestoneSet.parent + tally.milestoneSet.explicit} (${tally.milestoneSet.parent} from a parent, ${tally.milestoneSet.explicit} from --milestone)`
|
|
3065
|
+
});
|
|
3066
|
+
ctx.say({
|
|
3067
|
+
status: "info",
|
|
3068
|
+
label: "project",
|
|
3069
|
+
detail: `${plural(tally.projectSet, "issue")} ${dryRun ? "would be added" : "added"} from --project`
|
|
3070
|
+
});
|
|
3071
|
+
ctx.say({
|
|
3072
|
+
status: "heading",
|
|
3073
|
+
label: `Still lacking, among the ${plural(tally.examined, "item")} read${dryRun ? ", after the changes above" : ""}`
|
|
3074
|
+
});
|
|
3075
|
+
if (tally.skippedFields !== void 0) ctx.say({
|
|
3076
|
+
status: "info",
|
|
3077
|
+
label: "Priority, Effort",
|
|
3078
|
+
detail: `not listed: the issue fields could not be read (${tally.skippedFields})`
|
|
3079
|
+
});
|
|
3080
|
+
for (const [group, noun] of GROUPS) {
|
|
3081
|
+
if (!(group === "project" || group === "milestone" || fields.includes(group))) continue;
|
|
3082
|
+
const items = tally.lacking[group];
|
|
3083
|
+
ctx.say({
|
|
3084
|
+
status: items.length === 0 ? "ok" : "info",
|
|
3085
|
+
label: `without ${noun}`,
|
|
3086
|
+
detail: String(items.length)
|
|
3087
|
+
});
|
|
3088
|
+
for (const item of items) ctx.say({
|
|
3089
|
+
status: "info",
|
|
3090
|
+
label: `#${item.number}`,
|
|
3091
|
+
detail: `${item.state}: ${item.title}`
|
|
3092
|
+
});
|
|
3093
|
+
}
|
|
3094
|
+
if (more && tally.last !== void 0) ctx.say({
|
|
3095
|
+
status: "info",
|
|
3096
|
+
label: "resume",
|
|
3097
|
+
detail: `${rateLimited ? "GitHub's rate limit stopped the run" : "the limit was reached"}; to continue: ${resumeCommand(options, tally.last)}`
|
|
3098
|
+
});
|
|
3099
|
+
else if (more) ctx.say({
|
|
3100
|
+
status: "info",
|
|
3101
|
+
label: "resume",
|
|
3102
|
+
detail: "GitHub's rate limit stopped the run before it finished one item; run it again later"
|
|
3103
|
+
});
|
|
3104
|
+
else ctx.say({
|
|
3105
|
+
status: "info",
|
|
3106
|
+
label: "resume",
|
|
3107
|
+
detail: "the window is finished"
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
// src/probes/issue-types/backfill.ts
|
|
3111
|
+
/** The numbers the report is made of. */
|
|
3112
|
+
const emptyTally = () => ({
|
|
3113
|
+
examined: 0,
|
|
3114
|
+
pullRequestsSkipped: 0,
|
|
3115
|
+
typeSet: {},
|
|
3116
|
+
typed: 0,
|
|
3117
|
+
noKind: 0,
|
|
3118
|
+
ambiguous: [],
|
|
3119
|
+
areaLabelsAdded: 0,
|
|
3120
|
+
missingAreaLabels: /* @__PURE__ */ new Set(),
|
|
3121
|
+
milestoneSet: {
|
|
3122
|
+
parent: 0,
|
|
3123
|
+
explicit: 0
|
|
3124
|
+
},
|
|
3125
|
+
projectSet: 0,
|
|
3126
|
+
lacking: {
|
|
3127
|
+
project: [],
|
|
3128
|
+
milestone: [],
|
|
3129
|
+
priority: [],
|
|
3130
|
+
effort: []
|
|
3131
|
+
},
|
|
3132
|
+
failed: 0,
|
|
3133
|
+
last: void 0,
|
|
3134
|
+
skippedFields: void 0
|
|
3135
|
+
});
|
|
3136
|
+
/** How an issue is named in a row. */
|
|
3137
|
+
const labelOf = (item) => `#${item.number}`;
|
|
3138
|
+
/** Reads what the run needs before it starts: labels, the named milestone and project, the organization's issue fields. Says why and returns nothing when a name does not exist. */
|
|
3139
|
+
async function prepare(run, tally) {
|
|
3140
|
+
const { api, ctx, options } = run;
|
|
3141
|
+
const setup = {
|
|
3142
|
+
labelNames: await api.labelNames(),
|
|
3143
|
+
fields: []
|
|
3144
|
+
};
|
|
3145
|
+
if (options.milestone !== void 0) {
|
|
3146
|
+
setup.milestone = await api.milestoneNumber(options.milestone);
|
|
3147
|
+
if (setup.milestone === void 0) {
|
|
3148
|
+
ctx.say({
|
|
3149
|
+
status: "fail",
|
|
3150
|
+
label: "milestone",
|
|
3151
|
+
detail: `${options.milestone} is not a milestone of this repository`
|
|
3152
|
+
});
|
|
3153
|
+
return;
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
if (options.project !== void 0) {
|
|
3157
|
+
setup.projectId = await api.projectId(options.project);
|
|
3158
|
+
if (setup.projectId === void 0) {
|
|
3159
|
+
ctx.say({
|
|
3160
|
+
status: "fail",
|
|
3161
|
+
label: "project",
|
|
3162
|
+
detail: `${options.project} is not a project of this organization`
|
|
3163
|
+
});
|
|
3164
|
+
return;
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
const names = await api.fieldNames();
|
|
3168
|
+
if (typeof names === "string") tally.skippedFields = names;
|
|
3169
|
+
else setup.fields = ["priority", "effort"].filter((f) => names.has(f));
|
|
3170
|
+
return setup;
|
|
3171
|
+
}
|
|
3172
|
+
/** Does one issue or pull request; throws for a rate limit or a failed request, which the caller tells apart. */
|
|
3173
|
+
async function handle(run, setup, tally, item, projects) {
|
|
3174
|
+
const { api, ctx, areas, options } = run;
|
|
3175
|
+
const n = item.number;
|
|
3176
|
+
const wanted = item.isPullRequest ? areaLabelsForFiles(await api.files(n), areas.areas) : areaLabelsForTitle(item.title, areas.scopes);
|
|
3177
|
+
const have = new Set(item.labels.map((l) => l.toLowerCase()));
|
|
3178
|
+
const add = [];
|
|
3179
|
+
for (const label of wanted) {
|
|
3180
|
+
if (have.has(label.toLowerCase())) continue;
|
|
3181
|
+
if (setup.labelNames.has(label.toLowerCase())) add.push(label);
|
|
3182
|
+
else tally.missingAreaLabels.add(label);
|
|
3183
|
+
}
|
|
3184
|
+
if (add.length > 0) {
|
|
3185
|
+
await ctx.write(`add ${add.join(", ")} to ${labelOf(item)}`, () => api.addLabels(n, add));
|
|
3186
|
+
tally.areaLabelsAdded++;
|
|
3187
|
+
}
|
|
3188
|
+
if (item.isPullRequest) return;
|
|
3189
|
+
const type = planType(item);
|
|
3190
|
+
if ("set" in type) {
|
|
3191
|
+
await ctx.write(`set Type ${type.set} on ${labelOf(item)}`, () => api.setType(n, type.set));
|
|
3192
|
+
tally.typeSet[type.set] = (tally.typeSet[type.set] ?? 0) + 1;
|
|
3193
|
+
} else if (type.skip === "typed") tally.typed++;
|
|
3194
|
+
else if (type.skip === "no-kind-label") tally.noKind++;
|
|
3195
|
+
else tally.ambiguous.push({
|
|
3196
|
+
number: n,
|
|
3197
|
+
labels: type.labels
|
|
3198
|
+
});
|
|
3199
|
+
let milestone = item.milestone !== null;
|
|
3200
|
+
if (!milestone) {
|
|
3201
|
+
const parent = await api.parent(n);
|
|
3202
|
+
const fromParent = parent?.milestone;
|
|
3203
|
+
const target = fromParent ?? setup.milestone;
|
|
3204
|
+
if (target !== void 0) {
|
|
3205
|
+
const source = typeof fromParent === "number" ? "parent" : "explicit";
|
|
3206
|
+
const why = source === "parent" ? `from its parent #${parent?.number}` : `from --milestone ${options.milestone}`;
|
|
3207
|
+
await ctx.write(`set milestone on ${labelOf(item)} ${why}`, () => api.setMilestone(n, target));
|
|
3208
|
+
tally.milestoneSet[source]++;
|
|
3209
|
+
milestone = true;
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
if (!milestone) tally.lacking.milestone.push(item);
|
|
3213
|
+
let onProject = projects.length > 0;
|
|
3214
|
+
if (!onProject && setup.projectId !== void 0) {
|
|
3215
|
+
const id = setup.projectId;
|
|
3216
|
+
await ctx.write(`add ${labelOf(item)} to project ${options.project}`, () => api.addToProject(id, item.nodeId));
|
|
3217
|
+
tally.projectSet++;
|
|
3218
|
+
onProject = true;
|
|
3219
|
+
}
|
|
3220
|
+
if (!onProject) tally.lacking.project.push(item);
|
|
3221
|
+
if (setup.fields.length > 0) {
|
|
3222
|
+
const values = await api.fieldValues(n);
|
|
3223
|
+
for (const field of setup.fields) if (!values.has(field)) tally.lacking[field].push(item);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
/**
|
|
3227
|
+
* The backfill of `holocron probe github issue-types` (spec `tech-github-area-labels`, rollout item 5): reads a window of
|
|
3228
|
+
* issues, and for each adds what it can derive and nothing else.
|
|
3229
|
+
*
|
|
3230
|
+
* - **Type** from the kind labels (`bug`, `enhancement`, `chore`); one that has a Type keeps it, one with two kind labels
|
|
3231
|
+
* is listed and left.
|
|
3232
|
+
* - **Area labels** from the title's scope, or, for a pull request with `--pull-requests`, from its changed files; only
|
|
3233
|
+
* added, and only when the label exists (`holocron setup` makes them).
|
|
3234
|
+
* - **Milestone** from the issue's parent, else `--milestone` for an issue in the window named by `--issues` or `--since`.
|
|
3235
|
+
* - **Project** from `--project` for such an issue that is on no project.
|
|
3236
|
+
*
|
|
3237
|
+
* Nothing is overwritten and no label is removed. Priority and Effort are never set, only listed when missing. Every
|
|
3238
|
+
* change goes through `ctx.write`, so `--dry-run` says `would ...` and writes nothing. A rate limit ends the run with the
|
|
3239
|
+
* cursor to resume from; any other failure is a row for that issue and the run goes on.
|
|
3240
|
+
*/
|
|
3241
|
+
async function runBackfill(run) {
|
|
3242
|
+
const { ctx, api, options } = run;
|
|
3243
|
+
const tally = emptyTally();
|
|
3244
|
+
const setup = await prepare(run, tally);
|
|
3245
|
+
if (!setup) return;
|
|
3246
|
+
const read = await gather(api, options, run.isRateLimited);
|
|
3247
|
+
tally.pullRequestsSkipped = read.pullRequestsSkipped;
|
|
3248
|
+
const projects = /* @__PURE__ */ new Map();
|
|
3249
|
+
const ids = read.items.filter((i) => !i.isPullRequest).map((i) => i.nodeId);
|
|
3250
|
+
try {
|
|
3251
|
+
for (let at = 0; at < ids.length; at += 100) for (const [id, found] of await api.projectsOf(ids.slice(at, at + 100))) projects.set(id, found);
|
|
3252
|
+
} catch (err) {
|
|
3253
|
+
if (!run.isRateLimited(err)) throw err;
|
|
3254
|
+
read.rateLimited = true;
|
|
3255
|
+
read.more = true;
|
|
3256
|
+
read.items.length = 0;
|
|
3257
|
+
}
|
|
3258
|
+
let stopped = read.rateLimited;
|
|
3259
|
+
for (const item of read.items) {
|
|
3260
|
+
try {
|
|
3261
|
+
await handle(run, setup, tally, item, projects.get(item.nodeId) ?? []);
|
|
3262
|
+
} catch (err) {
|
|
3263
|
+
if (run.isRateLimited(err)) {
|
|
3264
|
+
stopped = true;
|
|
3265
|
+
break;
|
|
3266
|
+
}
|
|
3267
|
+
ctx.say({
|
|
3268
|
+
status: "fail",
|
|
3269
|
+
label: labelOf(item),
|
|
3270
|
+
detail: errorMessage(err)
|
|
3271
|
+
});
|
|
3272
|
+
tally.failed++;
|
|
3273
|
+
}
|
|
3274
|
+
tally.examined++;
|
|
3275
|
+
tally.last = item.number;
|
|
3276
|
+
}
|
|
3277
|
+
reportBackfill(ctx, {
|
|
3278
|
+
tally,
|
|
3279
|
+
options,
|
|
3280
|
+
dryRun: ctx.dryRun,
|
|
3281
|
+
more: read.more || stopped,
|
|
3282
|
+
rateLimited: stopped,
|
|
3283
|
+
fields: setup.fields
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
const VALUED = [
|
|
3287
|
+
"--issues",
|
|
3288
|
+
"--since",
|
|
3289
|
+
"--after",
|
|
3290
|
+
"--limit",
|
|
3291
|
+
"--milestone",
|
|
3292
|
+
"--project"
|
|
3293
|
+
];
|
|
3294
|
+
const INTEGER = /^\d+$/;
|
|
3295
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
3296
|
+
const MAX_RANGE = 1e3;
|
|
3297
|
+
/** `12,15,20-23` to `[12, 15, 20, 21, 22, 23]`, or `undefined` for text that is not such a list. */
|
|
3298
|
+
function numbersOf(text) {
|
|
3299
|
+
const out = [];
|
|
3300
|
+
for (const part of text.split(",")) {
|
|
3301
|
+
const [from, to, ...rest] = part.trim().split("-");
|
|
3302
|
+
if (rest.length > 0 || !INTEGER.test(from)) return void 0;
|
|
3303
|
+
const end = to === void 0 ? Number(from) : INTEGER.test(to) ? Number(to) : -1;
|
|
3304
|
+
if (end < Number(from) || end - Number(from) > MAX_RANGE) return void 0;
|
|
3305
|
+
for (let n = Number(from); n <= end; n++) out.push(n);
|
|
3306
|
+
}
|
|
3307
|
+
return out;
|
|
3308
|
+
}
|
|
3309
|
+
/** The words after `issue-types`, read into options, or the one thing wrong with them. */
|
|
3310
|
+
function parseArgs(args) {
|
|
3311
|
+
const options = {
|
|
3312
|
+
after: 0,
|
|
3313
|
+
limit: 100,
|
|
3314
|
+
pullRequests: false
|
|
3315
|
+
};
|
|
3316
|
+
for (let i = 0; i < args.length; i++) {
|
|
3317
|
+
const flag = args[i];
|
|
3318
|
+
if (flag === "--pull-requests") {
|
|
3319
|
+
options.pullRequests = true;
|
|
3320
|
+
continue;
|
|
3321
|
+
}
|
|
3322
|
+
if (!VALUED.includes(flag)) return {
|
|
3323
|
+
ok: false,
|
|
3324
|
+
message: `unknown argument ${flag}`
|
|
3325
|
+
};
|
|
3326
|
+
const value = args[++i];
|
|
3327
|
+
if (value === void 0 || value.startsWith("--")) return {
|
|
3328
|
+
ok: false,
|
|
3329
|
+
message: `${flag} needs a value`
|
|
3330
|
+
};
|
|
3331
|
+
if (flag === "--issues") {
|
|
3332
|
+
const issues = numbersOf(value);
|
|
3333
|
+
if (!issues) return {
|
|
3334
|
+
ok: false,
|
|
3335
|
+
message: `--issues takes numbers and ranges such as 12,15,20-25, not ${value}`
|
|
3336
|
+
};
|
|
3337
|
+
options.issues = issues;
|
|
3338
|
+
} else if (flag === "--since") {
|
|
3339
|
+
if (!DAY.test(value)) return {
|
|
3340
|
+
ok: false,
|
|
3341
|
+
message: `--since takes a day as YYYY-MM-DD, not ${value}`
|
|
3342
|
+
};
|
|
3343
|
+
options.since = value;
|
|
3344
|
+
} else if (flag === "--after") {
|
|
3345
|
+
if (!INTEGER.test(value)) return {
|
|
3346
|
+
ok: false,
|
|
3347
|
+
message: `--after takes a whole number, not ${value}`
|
|
3348
|
+
};
|
|
3349
|
+
options.after = Number(value);
|
|
3350
|
+
} else if (flag === "--limit") {
|
|
3351
|
+
if (!INTEGER.test(value) || Number(value) < 1) return {
|
|
3352
|
+
ok: false,
|
|
3353
|
+
message: `--limit takes a whole number of at least 1, not ${value}`
|
|
3354
|
+
};
|
|
3355
|
+
options.limit = Number(value);
|
|
3356
|
+
} else if (flag === "--milestone") options.milestone = value;
|
|
3357
|
+
else options.project = value;
|
|
3358
|
+
}
|
|
3359
|
+
if ((options.milestone || options.project) && !options.issues && !options.since) return {
|
|
3360
|
+
ok: false,
|
|
3361
|
+
message: "--milestone and --project need a window to apply to: name it with --issues or --since"
|
|
3362
|
+
};
|
|
3363
|
+
return {
|
|
3364
|
+
ok: true,
|
|
3365
|
+
options
|
|
3366
|
+
};
|
|
3367
|
+
}
|
|
3368
|
+
// src/probes/issue-types/issue-types.ts
|
|
3369
|
+
/**
|
|
3370
|
+
* `holocron probe github issue-types`: the one-time backfill of spec `tech-github-area-labels` (rollout item 5), a writer
|
|
3371
|
+
* the maintainer runs. It sets the Type of an issue from its kind labels, adds `area:<name>` labels, fills a milestone
|
|
3372
|
+
* and a project where a source exists, and ends with the list of every issue it read that still lacks a project, a
|
|
3373
|
+
* milestone, a Priority or an Effort. See `backfill.ts` for the rules. Run it with `--dry-run` first.
|
|
3374
|
+
*
|
|
3375
|
+
* Not verified against the live API: writing an issue's Type, adding an issue to a project, and the endpoints that read an
|
|
3376
|
+
* issue's field values and parent.
|
|
3377
|
+
*/
|
|
3378
|
+
function issueTypesProbe(ctx) {
|
|
3379
|
+
return {
|
|
3380
|
+
summary: "Backfill issues: set Type from the kind labels, add area labels, fill milestone and project where a source exists, and list what still lacks a project, milestone, Priority or Effort. Never overwrites a value. Run with --dry-run first.",
|
|
3381
|
+
writes: true,
|
|
3382
|
+
async run(probe) {
|
|
3383
|
+
const parsed = parseArgs(probe.args ?? []);
|
|
3384
|
+
if (!parsed.ok) {
|
|
3385
|
+
probe.say({
|
|
3386
|
+
status: "fail",
|
|
3387
|
+
label: "arguments",
|
|
3388
|
+
detail: parsed.message
|
|
3389
|
+
});
|
|
3390
|
+
return;
|
|
3391
|
+
}
|
|
3392
|
+
try {
|
|
3393
|
+
await runBackfill({
|
|
3394
|
+
ctx: probe,
|
|
3395
|
+
api: ctx.makeApi(),
|
|
3396
|
+
options: parsed.options,
|
|
3397
|
+
areas: ctx.areas,
|
|
3398
|
+
isRateLimited
|
|
3399
|
+
});
|
|
3400
|
+
} catch (err) {
|
|
3401
|
+
probe.say({
|
|
3402
|
+
status: "fail",
|
|
3403
|
+
label: "issue-types",
|
|
3404
|
+
detail: errorMessage(err)
|
|
3405
|
+
});
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
2803
3410
|
// src/probes/token/expectations.ts
|
|
2804
3411
|
/** The same rules in every layer that runs the workflow: a laptop (`local` inherits `dev`) and CI. */
|
|
2805
3412
|
function everywhere(rules) {
|
|
@@ -3314,6 +3921,10 @@ function createPlugin(options) {
|
|
|
3314
3921
|
resolve: (envName) => TOKEN_RESOLVERS[envName]?.(options),
|
|
3315
3922
|
tokenNames: Object.keys(TOKEN_RESOLVERS)
|
|
3316
3923
|
}),
|
|
3924
|
+
"issue-types": issueTypesProbe({
|
|
3925
|
+
makeApi: () => createBackfillApi(makeCtx(resolveIssuesToken).client, makeCtx(resolveOrgToken).client, options.repo),
|
|
3926
|
+
areas: options.areaLabels ?? {}
|
|
3927
|
+
}),
|
|
3317
3928
|
connection: connectionProbe({
|
|
3318
3929
|
provider: "GitHub",
|
|
3319
3930
|
url: options.baseUrl ?? "https://api.github.com",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-github",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.503",
|
|
4
4
|
"description": "Holocron plugin for GitHub. Implements source, ci, secrets, environments, and issues capabilities against the GitHub REST API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -44,21 +44,21 @@
|
|
|
44
44
|
"tsx": "4.23.15",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
46
|
"vitest": "^5.1.0",
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
48
|
-
"@theholocron/fs-utils": "^1.17.0-alpha.5",
|
|
49
|
-
"@theholocron/github-client": "^1.58.0-alpha.45",
|
|
47
|
+
"@theholocron/cli": "5.0.0-alpha.503",
|
|
50
48
|
"@theholocron/eslint-config": "^8.9.0-alpha.21",
|
|
51
|
-
"@theholocron/
|
|
49
|
+
"@theholocron/github-client": "^1.58.0-alpha.46",
|
|
50
|
+
"@theholocron/http-client": "^1.58.0-alpha.46",
|
|
51
|
+
"@theholocron/fs-utils": "^1.17.0-alpha.5",
|
|
52
52
|
"@theholocron/tsconfig": "^8.9.0-alpha.21",
|
|
53
|
-
"@theholocron/tsdown-config": "^8.9.0-alpha.21",
|
|
54
53
|
"@theholocron/misc-utils": "^1.17.0-alpha.5",
|
|
54
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.21",
|
|
55
55
|
"@theholocron/vitest-config": "^8.9.0-alpha.21"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@theholocron/fs-utils": "^1.16.0",
|
|
59
59
|
"@theholocron/github-client": "^1.58.0",
|
|
60
60
|
"@theholocron/misc-utils": "^1.16.0",
|
|
61
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
61
|
+
"@theholocron/cli": "5.0.0-alpha.503"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=22"
|