@lonca/baron-adapter-github 0.4.0 → 0.5.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 +17 -11
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -228,24 +228,30 @@ function createGithubScmTransport(options) {
228
228
  });
229
229
  return { id: String(data.id), url: data.html_url };
230
230
  },
231
- async findPullRequestByBranch(sourceBranch) {
231
+ async findPullRequestByBranch(sourceBranch, stateFilter) {
232
+ const listState = stateFilter === "open" ? "open" : stateFilter === "all" ? "all" : "closed";
232
233
  const { data } = await octokit.rest.pulls.list({
233
234
  owner,
234
235
  repo,
235
- state: "open",
236
+ state: listState,
236
237
  head: `${owner}:${sourceBranch}`,
237
- per_page: 1
238
+ sort: "created",
239
+ direction: "desc",
240
+ per_page: stateFilter === "open" || stateFilter === "all" ? 1 : 20
238
241
  });
239
- const pr = data[0];
240
- if (pr === void 0) return void 0;
242
+ const isMerged = (pr) => pr.merged_at != null;
243
+ const prState = (pr) => isMerged(pr) ? "merged" : pr.state === "closed" ? "closed" : "open";
244
+ const match = stateFilter === "merged" ? data.find(isMerged) : stateFilter === "closed" ? data.find((pr) => pr.state === "closed" && !isMerged(pr)) : data[0];
245
+ if (match === void 0) return void 0;
241
246
  return {
242
- id: String(pr.number),
243
- number: String(pr.number),
244
- title: pr.title,
245
- url: pr.html_url,
247
+ id: String(match.number),
248
+ number: String(match.number),
249
+ title: match.title,
250
+ url: match.html_url,
246
251
  sourceBranch,
247
- targetBranch: pr.base.ref,
248
- draft: pr.draft ?? false
252
+ targetBranch: match.base.ref,
253
+ draft: match.draft ?? false,
254
+ state: prState(match)
249
255
  };
250
256
  },
251
257
  async defaultBranch() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lonca/baron-adapter-github",
3
- "version": "0.4.0",
3
+ "version": "0.5.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.4.0"
19
+ "@lonca/baron-core": "0.5.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",
23
- "@lonca/baron-conformance": "0.4.0"
23
+ "@lonca/baron-conformance": "0.5.0"
24
24
  },
25
25
  "description": "Baron adapter for GitHub: issues, scm, ci, deploy.",
26
26
  "keywords": [