@lonca/baron-adapter-github 0.1.0 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +41 -1
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var GITHUB_PROVIDER = "github";
8
8
 
9
9
  // src/transport.ts
10
10
  import {
11
+ ASSIGNEE_ME,
11
12
  BaronError
12
13
  } from "@lonca/baron-core";
13
14
  import { Octokit } from "octokit";
@@ -20,6 +21,12 @@ function labelNames(labels) {
20
21
  function createGithubTransport(options) {
21
22
  const { owner, repo, token } = options;
22
23
  const octokit = new Octokit({ auth: token });
24
+ let myLogin;
25
+ const resolveAssignee = (assignee) => {
26
+ if (assignee !== ASSIGNEE_ME) return Promise.resolve(assignee);
27
+ myLogin ??= octokit.rest.users.getAuthenticated().then(({ data }) => data.login);
28
+ return myLogin;
29
+ };
23
30
  const toNative = (data, discriminator) => ({
24
31
  id: String(data.number),
25
32
  key: `#${data.number}`,
@@ -29,6 +36,7 @@ function createGithubTransport(options) {
29
36
  discriminator: discriminator ?? data.state ?? GH_STATE.OPEN,
30
37
  parentId: void 0,
31
38
  labels: labelNames(data.labels),
39
+ assignee: data.assignee?.login ?? void 0,
32
40
  url: data.html_url
33
41
  });
34
42
  return {
@@ -96,6 +104,15 @@ function createGithubTransport(options) {
96
104
  url: data.html_url
97
105
  };
98
106
  },
107
+ async assignIssue(id, assignee) {
108
+ const { data } = await octokit.rest.issues.update({
109
+ owner,
110
+ repo,
111
+ issue_number: Number(id),
112
+ assignees: [assignee]
113
+ });
114
+ return toNative(data);
115
+ },
99
116
  async linkIssues() {
100
117
  throw new BaronError(
101
118
  "GitHub has no native typed issue links; links are handled by the gap policy, not the transport.",
@@ -107,12 +124,14 @@ function createGithubTransport(options) {
107
124
  const label = query.target?.[TARGET.LABEL];
108
125
  const state = stateValue === GH_STATE.CLOSED ? GH_STATE.CLOSED : stateValue === GH_STATE.OPEN ? GH_STATE.OPEN : "all";
109
126
  const { limit } = query;
127
+ const assignee = query.assignee === void 0 ? void 0 : await resolveAssignee(query.assignee);
110
128
  const results = [];
111
129
  for await (const { data } of octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
112
130
  owner,
113
131
  repo,
114
132
  state,
115
133
  ...label !== void 0 ? { labels: label } : {},
134
+ ...assignee !== void 0 ? { assignee } : {},
116
135
  per_page: 100
117
136
  })) {
118
137
  for (const item of data) {
@@ -209,6 +228,26 @@ function createGithubScmTransport(options) {
209
228
  });
210
229
  return { id: String(data.id), url: data.html_url };
211
230
  },
231
+ async findPullRequestByBranch(sourceBranch) {
232
+ const { data } = await octokit.rest.pulls.list({
233
+ owner,
234
+ repo,
235
+ state: "open",
236
+ head: `${owner}:${sourceBranch}`,
237
+ per_page: 1
238
+ });
239
+ const pr = data[0];
240
+ if (pr === void 0) return void 0;
241
+ return {
242
+ id: String(pr.number),
243
+ number: String(pr.number),
244
+ title: pr.title,
245
+ url: pr.html_url,
246
+ sourceBranch,
247
+ targetBranch: pr.base.ref,
248
+ draft: pr.draft ?? false
249
+ };
250
+ },
212
251
  async defaultBranch() {
213
252
  const { data } = await octokit.rest.repos.get({ owner, repo });
214
253
  return data.default_branch;
@@ -499,7 +538,8 @@ var githubManifest = {
499
538
  arbitraryStates: false,
500
539
  nativeLabels: true,
501
540
  comments: true,
502
- issueLinks: false
541
+ issueLinks: false,
542
+ assignment: true
503
543
  }
504
544
  };
505
545
  var exampleGithubRoleMap = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lonca/baron-adapter-github",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -16,11 +16,11 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "octokit": "^5.0.5",
19
- "@lonca/baron-core": "0.1.0"
19
+ "@lonca/baron-core": "0.3.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",
23
- "@lonca/baron-conformance": "0.1.0"
23
+ "@lonca/baron-conformance": "0.3.0"
24
24
  },
25
25
  "description": "Baron adapter for GitHub: issues, scm, ci, deploy.",
26
26
  "keywords": [