@lonca/baron-adapter-github 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @lonca/baron-adapter-github
2
+
3
+ Baron adapter for GitHub: issues, scm, ci, deploy.
4
+
5
+ Part of **[Baron](https://github.com/loncadev/baron)** — a platform-agnostic work-orchestration layer for AI coding agents:
6
+ one pane of glass (issues, scm, ci, deploy, notify) across providers, via MCP + CLI.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @lonca/baron-adapter-github
12
+ ```
13
+
14
+ ## Documentation
15
+
16
+ See the [Baron documentation](https://github.com/loncadev/baron#readme). Source: [`packages/adapters/github`](https://github.com/loncadev/baron/tree/main/packages/adapters/github).
17
+
18
+ ## License
19
+
20
+ [Apache-2.0](./LICENSE) © Baron contributors.
@@ -0,0 +1,92 @@
1
+ import { IssuesTransport, Introspector, ScmTransport, GapPolicy, Logger, BaseScmAdapter, ScmManifest, CiTransport, BaseCiAdapter, CiManifest, CiStatusMaps, DeployTransport, BaseDeployAdapter, DeployManifest, DeployStatusMaps, IssuesProviderConfig, BaseIssuesAdapter, LinkMap, ProviderRoleMap, TypeMap, CapabilityManifest } from '@lonca/baron-core';
2
+
3
+ /**
4
+ * The GitHub provider id. Kept in its own leaf module (no imports) so the transport, introspector,
5
+ * and scm modules can read it WITHOUT importing `index.ts` — `index.ts` re-exports those modules, so
6
+ * referencing an `index.ts` const at their module top-level would hit a circular temporal-dead-zone
7
+ * error under real ESM evaluation order.
8
+ */
9
+ declare const GITHUB_PROVIDER = "github";
10
+
11
+ interface GithubTransportOptions {
12
+ readonly owner: string;
13
+ readonly repo: string;
14
+ /** Fine-grained PAT or token. Read from env / secret-manager by the caller; never committed. */
15
+ readonly token: string;
16
+ }
17
+ /**
18
+ * Live transport over the GitHub REST API (octokit). Baron's issue `id` is the per-repo issue
19
+ * NUMBER (every REST path keys on `issue_number`); hierarchy is emulated by the core via labels, so
20
+ * this transport never deals with parents. The role-bearing discriminator is a label, so writes
21
+ * ECHO `target.label` back as the discriminator (a cold {@link getIssue} can only report open/closed
22
+ * — recovering a mid-workflow role from labels would need the role map, which invariant #4 forbids
23
+ * the transport from holding; this lossy cold read is the same documented debt as type-role reverse
24
+ * resolution).
25
+ */
26
+ declare function createGithubTransport(options: GithubTransportOptions): IssuesTransport;
27
+
28
+ /**
29
+ * Live introspection over the GitHub REST API. GitHub's issue vocabulary is mostly fixed: states
30
+ * are binary (open/closed) and workflow nuance rides on labels, so `stateKey` is 'label' and the
31
+ * states are the two intrinsic terminals. Native issue TYPES are an org opt-in feature (often
32
+ * disabled); when present they enrich `workItemTypes`, otherwise it collapses to a single 'issue'.
33
+ * Board columns and iterations live in the separate Projects v2 GraphQL API and are omitted here.
34
+ */
35
+ declare function createGithubIntrospector(options: GithubTransportOptions): Introspector;
36
+
37
+ /** GitHub supports draft PRs and PR discussion (PR-level issue comments). */
38
+ declare const githubScmManifest: ScmManifest;
39
+ /**
40
+ * Live `scm` transport over the GitHub REST API (octokit). Branches are created via the git refs
41
+ * API (read the base ref's sha, create a new ref). A PR "thread" is a PR-level discussion comment —
42
+ * GitHub models PRs as issues, so it is an issue comment on the PR number (a positioned review
43
+ * thread would need a diff location, which the abstract primitive does not carry).
44
+ */
45
+ declare function createGithubScmTransport(options: GithubTransportOptions): ScmTransport;
46
+ declare function defineGithubScmAdapter(transport: ScmTransport, gapPolicy?: GapPolicy, logger?: Logger): BaseScmAdapter;
47
+
48
+ /** GitHub Actions capabilities. A run's jobs are surfaced as stages in run detail. */
49
+ declare const githubCiManifest: CiManifest;
50
+ /**
51
+ * GitHub Actions' fixed string enums → normalized RunStatus. A completed run is decided by its
52
+ * `conclusion`; an in-flight run by its `status`. 'completed' is intentionally absent from the status
53
+ * map so a finished run is always classified by its conclusion (which is null until then).
54
+ */
55
+ declare const githubCiStatusMaps: CiStatusMaps;
56
+ /**
57
+ * Live `ci` transport over the GitHub Actions REST API (octokit). Read-only in slice 1. Run logs are
58
+ * a zip archive on GitHub, so `fetchLogs` tails the last job's plain-text log instead.
59
+ */
60
+ declare function createGithubCiTransport(options: GithubTransportOptions): CiTransport;
61
+ declare function defineGithubCiAdapter(transport: CiTransport, gapPolicy?: GapPolicy, logger?: Logger): BaseCiAdapter;
62
+
63
+ /** GitHub Environments + Deployments. Read-only (no create) in this slice. */
64
+ declare const githubDeployManifest: DeployManifest;
65
+ /** GitHub deployment-status `state` strings → normalized DeployStatus (no separate result axis). */
66
+ declare const githubDeployStatusMaps: DeployStatusMaps;
67
+ declare function createGithubDeployTransport(options: GithubTransportOptions): DeployTransport;
68
+ declare function defineGithubDeployAdapter(transport: DeployTransport, gapPolicy?: GapPolicy, logger?: Logger): BaseDeployAdapter;
69
+
70
+ /**
71
+ * GitHub Issues is deliberately flat: no native parent/child hierarchy (sub-issues exist but are
72
+ * a separate primitive), and only binary open/closed states. Workflow states beyond that must be
73
+ * emulated (Baron does this via labels). This is the divergent counterpart to Azure and the
74
+ * reason the impedance layer earns its keep.
75
+ */
76
+ declare const githubManifest: CapabilityManifest;
77
+ /** Example role map: mid-workflow roles ride on labels, `done` closes the issue. */
78
+ declare const exampleGithubRoleMap: ProviderRoleMap;
79
+ /** GitHub has one issue type; every type role maps onto a plain issue. */
80
+ declare const exampleGithubTypeMap: TypeMap;
81
+ /** GitHub has no native typed links; links are emulated/degraded per the gap policy, so this is empty. */
82
+ declare const exampleGithubLinkMap: LinkMap;
83
+ /**
84
+ * Recommended gap policy for GitHub: emulate hierarchy and arbitrary states via labels, and drop
85
+ * sprints with a warning. Installations may override; the point is the choice is explicit, not a
86
+ * silent default baked into the adapter.
87
+ */
88
+ declare const recommendedGithubGapPolicy: GapPolicy;
89
+ type GithubIssuesConfig = Omit<IssuesProviderConfig, 'provider'>;
90
+ declare function defineGithubIssuesAdapter(config: GithubIssuesConfig, transport: IssuesTransport, logger?: Logger): BaseIssuesAdapter;
91
+
92
+ export { GITHUB_PROVIDER, type GithubIssuesConfig, type GithubTransportOptions, createGithubCiTransport, createGithubDeployTransport, createGithubIntrospector, createGithubScmTransport, createGithubTransport, defineGithubCiAdapter, defineGithubDeployAdapter, defineGithubIssuesAdapter, defineGithubScmAdapter, exampleGithubLinkMap, exampleGithubRoleMap, exampleGithubTypeMap, githubCiManifest, githubCiStatusMaps, githubDeployManifest, githubDeployStatusMaps, githubManifest, githubScmManifest, recommendedGithubGapPolicy };
package/dist/index.js ADDED
@@ -0,0 +1,555 @@
1
+ // src/index.ts
2
+ import {
3
+ BaseIssuesAdapter
4
+ } from "@lonca/baron-core";
5
+
6
+ // src/provider.ts
7
+ var GITHUB_PROVIDER = "github";
8
+
9
+ // src/transport.ts
10
+ import {
11
+ BaronError
12
+ } from "@lonca/baron-core";
13
+ import { Octokit } from "octokit";
14
+ var GH_STATE = { OPEN: "open", CLOSED: "closed" };
15
+ var TARGET = { STATE: "state", LABEL: "label" };
16
+ var GH_NATIVE_TYPE = "issue";
17
+ function labelNames(labels) {
18
+ return labels.map((label) => typeof label === "string" ? label : label.name ?? "").filter((name) => name.length > 0);
19
+ }
20
+ function createGithubTransport(options) {
21
+ const { owner, repo, token } = options;
22
+ const octokit = new Octokit({ auth: token });
23
+ const toNative = (data, discriminator) => ({
24
+ id: String(data.number),
25
+ key: `#${data.number}`,
26
+ title: data.title,
27
+ body: data.body ?? void 0,
28
+ nativeType: GH_NATIVE_TYPE,
29
+ discriminator: discriminator ?? data.state ?? GH_STATE.OPEN,
30
+ parentId: void 0,
31
+ labels: labelNames(data.labels),
32
+ url: data.html_url
33
+ });
34
+ return {
35
+ async createIssue(input) {
36
+ const { data } = await octokit.rest.issues.create({
37
+ owner,
38
+ repo,
39
+ title: input.title,
40
+ ...input.body !== void 0 ? { body: input.body } : {},
41
+ labels: [...input.labels]
42
+ });
43
+ return toNative(data);
44
+ },
45
+ async getIssue(id) {
46
+ const { data } = await octokit.rest.issues.get({ owner, repo, issue_number: Number(id) });
47
+ return toNative(data);
48
+ },
49
+ async applyTarget(id, target) {
50
+ const issue_number = Number(id);
51
+ const roleLabel = target[TARGET.LABEL];
52
+ const state = target[TARGET.STATE];
53
+ if (roleLabel !== void 0) {
54
+ await octokit.rest.issues.addLabels({ owner, repo, issue_number, labels: [roleLabel] });
55
+ }
56
+ if (state === GH_STATE.CLOSED) {
57
+ await octokit.rest.issues.update({
58
+ owner,
59
+ repo,
60
+ issue_number,
61
+ state: GH_STATE.CLOSED,
62
+ state_reason: "completed"
63
+ });
64
+ } else if (state === GH_STATE.OPEN) {
65
+ await octokit.rest.issues.update({
66
+ owner,
67
+ repo,
68
+ issue_number,
69
+ state: GH_STATE.OPEN,
70
+ state_reason: "reopened"
71
+ });
72
+ }
73
+ const { data } = await octokit.rest.issues.get({ owner, repo, issue_number });
74
+ return toNative(data, roleLabel ?? state);
75
+ },
76
+ async addLabel(id, label) {
77
+ await octokit.rest.issues.addLabels({
78
+ owner,
79
+ repo,
80
+ issue_number: Number(id),
81
+ labels: [label]
82
+ });
83
+ },
84
+ async addComment(id, body) {
85
+ const { data } = await octokit.rest.issues.createComment({
86
+ owner,
87
+ repo,
88
+ issue_number: Number(id),
89
+ body
90
+ });
91
+ return {
92
+ id: String(data.id),
93
+ body: data.body ?? body,
94
+ author: data.user?.login,
95
+ createdAt: data.created_at,
96
+ url: data.html_url
97
+ };
98
+ },
99
+ async linkIssues() {
100
+ throw new BaronError(
101
+ "GitHub has no native typed issue links; links are handled by the gap policy, not the transport.",
102
+ "NOT_SUPPORTED"
103
+ );
104
+ },
105
+ async queryIssues(query) {
106
+ const stateValue = query.target?.[TARGET.STATE];
107
+ const label = query.target?.[TARGET.LABEL];
108
+ const state = stateValue === GH_STATE.CLOSED ? GH_STATE.CLOSED : stateValue === GH_STATE.OPEN ? GH_STATE.OPEN : "all";
109
+ const { limit } = query;
110
+ const results = [];
111
+ for await (const { data } of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
112
+ owner,
113
+ repo,
114
+ state,
115
+ ...label !== void 0 ? { labels: label } : {},
116
+ per_page: 100
117
+ })) {
118
+ for (const item of data) {
119
+ if (item.pull_request !== void 0) continue;
120
+ results.push(toNative(item));
121
+ if (limit !== void 0 && results.length >= limit) return results;
122
+ }
123
+ }
124
+ return results;
125
+ }
126
+ };
127
+ }
128
+
129
+ // src/introspector.ts
130
+ import { Octokit as Octokit2 } from "octokit";
131
+ function createGithubIntrospector(options) {
132
+ const { owner, repo, token } = options;
133
+ const octokit = new Octokit2({ auth: token });
134
+ return {
135
+ async introspect() {
136
+ let workItemTypes = [{ name: "issue" }];
137
+ try {
138
+ const request = octokit.request;
139
+ const { data } = await request("GET /repos/{owner}/{repo}/issue-types", { owner, repo });
140
+ if (Array.isArray(data) && data.length > 0) {
141
+ workItemTypes = data.map((entry) => ({
142
+ name: String(entry.name ?? "issue")
143
+ }));
144
+ }
145
+ } catch {
146
+ }
147
+ return {
148
+ provider: GITHUB_PROVIDER,
149
+ stateKey: "label",
150
+ workItemTypes,
151
+ states: [
152
+ { name: "open", category: "proposed" },
153
+ { name: "closed", category: "completed" }
154
+ ]
155
+ };
156
+ }
157
+ };
158
+ }
159
+
160
+ // src/scm.ts
161
+ import {
162
+ BaseScmAdapter
163
+ } from "@lonca/baron-core";
164
+ import { Octokit as Octokit3 } from "octokit";
165
+ var githubScmManifest = {
166
+ provider: GITHUB_PROVIDER,
167
+ scm: { draftPullRequests: true, pullRequestThreads: true }
168
+ };
169
+ function createGithubScmTransport(options) {
170
+ const { owner, repo, token } = options;
171
+ const octokit = new Octokit3({ auth: token });
172
+ return {
173
+ async createBranch(name, fromBranch) {
174
+ const base = await octokit.rest.git.getRef({ owner, repo, ref: `heads/${fromBranch}` });
175
+ const created = await octokit.rest.git.createRef({
176
+ owner,
177
+ repo,
178
+ ref: `refs/heads/${name}`,
179
+ sha: base.data.object.sha
180
+ });
181
+ return { name, sha: created.data.object.sha, url: created.data.url };
182
+ },
183
+ async createPullRequest(input) {
184
+ const { data } = await octokit.rest.pulls.create({
185
+ owner,
186
+ repo,
187
+ title: input.title,
188
+ ...input.body !== void 0 ? { body: input.body } : {},
189
+ head: input.sourceBranch,
190
+ base: input.targetBranch,
191
+ draft: input.draft
192
+ });
193
+ return {
194
+ id: String(data.number),
195
+ number: String(data.number),
196
+ title: data.title,
197
+ url: data.html_url,
198
+ sourceBranch: input.sourceBranch,
199
+ targetBranch: input.targetBranch,
200
+ draft: data.draft ?? input.draft
201
+ };
202
+ },
203
+ async addPullRequestThread(pullRequestId, body) {
204
+ const { data } = await octokit.rest.issues.createComment({
205
+ owner,
206
+ repo,
207
+ issue_number: Number(pullRequestId),
208
+ body
209
+ });
210
+ return { id: String(data.id), url: data.html_url };
211
+ },
212
+ async defaultBranch() {
213
+ const { data } = await octokit.rest.repos.get({ owner, repo });
214
+ return data.default_branch;
215
+ },
216
+ async getPullRequestStatus(pullRequestId) {
217
+ const prNum = Number(pullRequestId);
218
+ const { data: pr } = await octokit.rest.pulls.get({ owner, repo, pull_number: prNum });
219
+ const state = pr.merged ? "merged" : pr.state === "closed" ? "closed" : pr.state === "open" ? "open" : "unknown";
220
+ const { data: reviews } = await octokit.rest.pulls.listReviews({
221
+ owner,
222
+ repo,
223
+ pull_number: prNum,
224
+ per_page: 100
225
+ });
226
+ const latest = /* @__PURE__ */ new Map();
227
+ let hadComment = false;
228
+ for (const r of reviews) {
229
+ const login = r.user?.login;
230
+ if (login === void 0) continue;
231
+ if (r.state === "APPROVED" || r.state === "CHANGES_REQUESTED") latest.set(login, r.state);
232
+ else if (r.state === "DISMISSED") latest.delete(login);
233
+ else if (r.state === "COMMENTED") hadComment = true;
234
+ }
235
+ const states = [...latest.values()];
236
+ const reviewDecision = states.includes("CHANGES_REQUESTED") ? "changes_requested" : states.includes("APPROVED") ? "approved" : (
237
+ // engaged (commented) but undecided → pending; no engagement at all → review_required.
238
+ hadComment ? "pending" : "review_required"
239
+ );
240
+ const { data: checks } = await octokit.rest.checks.listForRef({
241
+ owner,
242
+ repo,
243
+ ref: pr.head.sha,
244
+ per_page: 100
245
+ });
246
+ let succeeded = 0;
247
+ let failed = 0;
248
+ let pending = 0;
249
+ for (const c of checks.check_runs) {
250
+ if (c.status !== "completed") pending += 1;
251
+ else if (c.conclusion === "success" || c.conclusion === "neutral" || c.conclusion === "skipped")
252
+ succeeded += 1;
253
+ else failed += 1;
254
+ }
255
+ const total = checks.check_runs.length;
256
+ const rollup = total === 0 ? "none" : failed > 0 ? "failed" : pending > 0 ? "pending" : "succeeded";
257
+ return {
258
+ id: String(pr.number),
259
+ state,
260
+ reviewDecision,
261
+ ...pr.mergeable != null ? { mergeable: pr.mergeable } : {},
262
+ checks: { total, succeeded, failed, pending, rollup },
263
+ url: pr.html_url
264
+ };
265
+ }
266
+ };
267
+ }
268
+ function defineGithubScmAdapter(transport, gapPolicy, logger) {
269
+ return new BaseScmAdapter(githubScmManifest, transport, gapPolicy, logger);
270
+ }
271
+
272
+ // src/ci.ts
273
+ import {
274
+ BaseCiAdapter
275
+ } from "@lonca/baron-core";
276
+ import { Octokit as Octokit4 } from "octokit";
277
+ var githubCiManifest = {
278
+ provider: GITHUB_PROVIDER,
279
+ ci: {
280
+ canTrigger: true,
281
+ canCancel: true,
282
+ hasStages: true,
283
+ hasApprovalGates: true,
284
+ providesLogs: true,
285
+ hasArtifacts: true
286
+ }
287
+ };
288
+ var githubCiStatusMaps = {
289
+ status: {
290
+ queued: "queued",
291
+ in_progress: "running",
292
+ requested: "queued",
293
+ waiting: "waiting",
294
+ pending: "queued"
295
+ },
296
+ result: {
297
+ success: "succeeded",
298
+ failure: "failed",
299
+ cancelled: "canceled",
300
+ skipped: "skipped",
301
+ timed_out: "failed",
302
+ action_required: "waiting",
303
+ neutral: "succeeded",
304
+ startup_failure: "failed"
305
+ }
306
+ };
307
+ var DEFAULT_RUN_LIMIT = 50;
308
+ var DEFAULT_TAIL_LINES = 200;
309
+ function toNativeRun(r) {
310
+ return {
311
+ id: String(r.id),
312
+ pipelineId: String(r.workflow_id ?? ""),
313
+ pipelineName: r.name ?? void 0,
314
+ status: r.status ?? "queued",
315
+ // conclusion is null until the run finishes; treat that as "no result yet" so status classifies it.
316
+ result: r.conclusion ?? void 0,
317
+ branch: r.head_branch ?? void 0,
318
+ number: r.run_number !== void 0 ? String(r.run_number) : void 0,
319
+ url: r.html_url,
320
+ createdAt: r.created_at,
321
+ finishedAt: r.updated_at
322
+ };
323
+ }
324
+ function createGithubCiTransport(options) {
325
+ const { owner, repo, token } = options;
326
+ const octokit = new Octokit4({ auth: token });
327
+ return {
328
+ async listPipelines(query) {
329
+ const { data } = await octokit.rest.actions.listRepoWorkflows({
330
+ owner,
331
+ repo,
332
+ per_page: query.limit ?? 100
333
+ });
334
+ return data.workflows.map((w) => ({ id: String(w.id), name: w.name, url: w.html_url }));
335
+ },
336
+ async listRuns(query) {
337
+ const { data } = await octokit.rest.actions.listWorkflowRunsForRepo({
338
+ owner,
339
+ repo,
340
+ ...query.branch !== void 0 ? { branch: query.branch } : {},
341
+ per_page: query.limit ?? DEFAULT_RUN_LIMIT
342
+ });
343
+ const runs = data.workflow_runs.map(toNativeRun);
344
+ return query.pipelineId !== void 0 ? runs.filter((r) => r.pipelineId === query.pipelineId) : runs;
345
+ },
346
+ async getRun(id) {
347
+ const { data } = await octokit.rest.actions.getWorkflowRun({
348
+ owner,
349
+ repo,
350
+ run_id: Number(id)
351
+ });
352
+ const jobsResp = await octokit.rest.actions.listJobsForWorkflowRun({
353
+ owner,
354
+ repo,
355
+ run_id: Number(id),
356
+ per_page: 100
357
+ });
358
+ const stages = jobsResp.data.jobs.map((j) => ({
359
+ name: j.name,
360
+ status: j.status,
361
+ result: j.conclusion ?? void 0
362
+ }));
363
+ return { ...toNativeRun(data), stages };
364
+ },
365
+ async fetchLogs(runId, options2) {
366
+ const jobs = await octokit.rest.actions.listJobsForWorkflowRun({
367
+ owner,
368
+ repo,
369
+ run_id: Number(runId),
370
+ per_page: 100
371
+ });
372
+ const list = jobs.data.jobs;
373
+ const last = list[list.length - 1];
374
+ if (last === void 0) return { content: "", truncated: false };
375
+ const logResp = await octokit.rest.actions.downloadJobLogsForWorkflowRun({
376
+ owner,
377
+ repo,
378
+ job_id: last.id
379
+ });
380
+ const lines = String(logResp.data ?? "").split("\n");
381
+ const tail = options2.tailLines ?? DEFAULT_TAIL_LINES;
382
+ const start = Math.max(0, lines.length - tail);
383
+ return { content: lines.slice(start).join("\n"), truncated: start > 0 || list.length > 1 };
384
+ },
385
+ async triggerRun(input) {
386
+ const ref = input.ref ?? (await octokit.rest.repos.get({ owner, repo })).data.default_branch;
387
+ await octokit.rest.actions.createWorkflowDispatch({
388
+ owner,
389
+ repo,
390
+ workflow_id: Number(input.pipelineId),
391
+ ref,
392
+ ...input.variables !== void 0 ? { inputs: input.variables } : {}
393
+ });
394
+ return { accepted: true };
395
+ },
396
+ async cancelRun(runId) {
397
+ await octokit.rest.actions.cancelWorkflowRun({ owner, repo, run_id: Number(runId) });
398
+ const { data } = await octokit.rest.actions.getWorkflowRun({
399
+ owner,
400
+ repo,
401
+ run_id: Number(runId)
402
+ });
403
+ return toNativeRun(data);
404
+ }
405
+ };
406
+ }
407
+ function defineGithubCiAdapter(transport, gapPolicy, logger) {
408
+ return new BaseCiAdapter(githubCiManifest, githubCiStatusMaps, transport, gapPolicy, logger);
409
+ }
410
+
411
+ // src/deploy.ts
412
+ import {
413
+ BaseDeployAdapter
414
+ } from "@lonca/baron-core";
415
+ import { Octokit as Octokit5 } from "octokit";
416
+ var githubDeployManifest = {
417
+ provider: GITHUB_PROVIDER,
418
+ deploy: { environments: true, deployments: true, canTrigger: false }
419
+ };
420
+ var githubDeployStatusMaps = {
421
+ status: {
422
+ queued: "pending",
423
+ pending: "pending",
424
+ waiting: "pending",
425
+ in_progress: "running",
426
+ success: "succeeded",
427
+ failure: "failed",
428
+ error: "failed",
429
+ inactive: "unknown"
430
+ },
431
+ result: {}
432
+ };
433
+ var DEFAULT_LIMIT = 20;
434
+ function createGithubDeployTransport(options) {
435
+ const { owner, repo, token } = options;
436
+ const octokit = new Octokit5({ auth: token });
437
+ return {
438
+ async listEnvironments(query) {
439
+ const { data } = await octokit.rest.repos.getAllEnvironments({
440
+ owner,
441
+ repo,
442
+ per_page: query.limit ?? 100
443
+ });
444
+ return (data.environments ?? []).map((e) => ({
445
+ id: String(e.id),
446
+ name: e.name,
447
+ url: e.html_url
448
+ }));
449
+ },
450
+ async listDeployments(query) {
451
+ const { data } = await octokit.rest.repos.listDeployments({
452
+ owner,
453
+ repo,
454
+ ...query.environment !== void 0 ? { environment: query.environment } : {},
455
+ per_page: query.limit ?? DEFAULT_LIMIT
456
+ });
457
+ return Promise.all(
458
+ data.map(async (d) => {
459
+ const statuses = await octokit.rest.repos.listDeploymentStatuses({
460
+ owner,
461
+ repo,
462
+ deployment_id: d.id,
463
+ per_page: 1
464
+ });
465
+ const latest = statuses.data[0];
466
+ return {
467
+ id: String(d.id),
468
+ environment: typeof d.environment === "string" ? d.environment : "",
469
+ ...latest !== void 0 ? { status: latest.state } : {},
470
+ ref: typeof d.ref === "string" ? d.ref : void 0,
471
+ sha: d.sha,
472
+ ...typeof d.created_at === "string" ? { createdAt: d.created_at } : {},
473
+ // The deployment's own updated_at is its finish time — not the status record's created_at.
474
+ ...typeof d.updated_at === "string" ? { finishedAt: d.updated_at } : {}
475
+ };
476
+ })
477
+ );
478
+ }
479
+ };
480
+ }
481
+ function defineGithubDeployAdapter(transport, gapPolicy, logger) {
482
+ return new BaseDeployAdapter(
483
+ githubDeployManifest,
484
+ githubDeployStatusMaps,
485
+ transport,
486
+ gapPolicy,
487
+ logger
488
+ );
489
+ }
490
+
491
+ // src/index.ts
492
+ var githubManifest = {
493
+ provider: GITHUB_PROVIDER,
494
+ issues: {
495
+ hierarchy: false,
496
+ subIssues: true,
497
+ separateBoardColumn: false,
498
+ sprints: false,
499
+ arbitraryStates: false,
500
+ nativeLabels: true,
501
+ comments: true,
502
+ issueLinks: false
503
+ }
504
+ };
505
+ var exampleGithubRoleMap = {
506
+ stateKey: "label",
507
+ states: {
508
+ in_progress: { label: "in-progress" },
509
+ in_review: { label: "in-review" },
510
+ done: { state: "closed", label: "done" }
511
+ }
512
+ };
513
+ var exampleGithubTypeMap = {
514
+ epic: "issue",
515
+ story: "issue",
516
+ task: "issue",
517
+ subtask: "issue"
518
+ };
519
+ var exampleGithubLinkMap = {};
520
+ var recommendedGithubGapPolicy = {
521
+ hierarchy: { kind: "emulate", strategy: "labels" },
522
+ arbitraryStates: { kind: "emulate", strategy: "labels" },
523
+ sprints: { kind: "degrade" },
524
+ issueLinks: { kind: "emulate", strategy: "labels" }
525
+ };
526
+ function defineGithubIssuesAdapter(config, transport, logger) {
527
+ return new BaseIssuesAdapter(
528
+ githubManifest,
529
+ { linkMap: exampleGithubLinkMap, ...config, provider: GITHUB_PROVIDER },
530
+ transport,
531
+ logger
532
+ );
533
+ }
534
+ export {
535
+ GITHUB_PROVIDER,
536
+ createGithubCiTransport,
537
+ createGithubDeployTransport,
538
+ createGithubIntrospector,
539
+ createGithubScmTransport,
540
+ createGithubTransport,
541
+ defineGithubCiAdapter,
542
+ defineGithubDeployAdapter,
543
+ defineGithubIssuesAdapter,
544
+ defineGithubScmAdapter,
545
+ exampleGithubLinkMap,
546
+ exampleGithubRoleMap,
547
+ exampleGithubTypeMap,
548
+ githubCiManifest,
549
+ githubCiStatusMaps,
550
+ githubDeployManifest,
551
+ githubDeployStatusMaps,
552
+ githubManifest,
553
+ githubScmManifest,
554
+ recommendedGithubGapPolicy
555
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@lonca/baron-adapter-github",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "Apache-2.0",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "octokit": "^5.0.5",
19
+ "@lonca/baron-core": "0.1.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^22.0.0",
23
+ "@lonca/baron-conformance": "0.1.0"
24
+ },
25
+ "description": "Baron adapter for GitHub: issues, scm, ci, deploy.",
26
+ "keywords": [
27
+ "baron",
28
+ "ai-agents",
29
+ "mcp",
30
+ "work-orchestration",
31
+ "devops",
32
+ "github",
33
+ "adapter"
34
+ ],
35
+ "author": "Baron contributors",
36
+ "homepage": "https://github.com/loncadev/baron#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/loncadev/baron/issues"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/loncadev/baron.git",
43
+ "directory": "packages/adapters/github"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup src/index.ts --format esm --dts --clean",
47
+ "typecheck": "tsc --noEmit"
48
+ }
49
+ }