@tahminator/pipeline 1.0.73 → 1.0.74

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.
@@ -1,12 +1,14 @@
1
1
  import { GitHubOutputManager } from "./output";
2
2
  import { GitHubPRManager } from "./pr";
3
3
  import { GitHubTagManager } from "./tag";
4
+ import { GitHubTeamManager } from "./team";
4
5
  export declare class GitHubClient {
5
6
  private readonly client;
6
7
  private readonly isExplicitToken;
7
8
  private readonly tagManager;
8
9
  private readonly outputManager;
9
10
  private readonly prManager;
11
+ private readonly teamManager;
10
12
  private constructor();
11
13
  /**
12
14
  * @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
@@ -39,4 +41,6 @@ export declare class GitHubClient {
39
41
  outputToGithubOutput(...args: Parameters<GitHubOutputManager["outputToGithubOutput"]>): Promise<void>;
40
42
  updateK8sTagWithPR(...args: Parameters<GitHubPRManager["updateK8sTagWithPR"]>): Promise<void>;
41
43
  sendPrMessage(...args: Parameters<GitHubPRManager["sendPrMessage"]>): Promise<void>;
44
+ mergePr(...args: Parameters<GitHubPRManager["mergePr"]>): Promise<void>;
45
+ isTeamMember(...args: Parameters<GitHubTeamManager["isTeamMember"]>): Promise<boolean>;
42
46
  }
package/dist/gh/client.js CHANGED
@@ -3,18 +3,21 @@ import { Octokit } from "@octokit/rest";
3
3
  import { GitHubOutputManager } from "./output";
4
4
  import { GitHubPRManager } from "./pr";
5
5
  import { GitHubTagManager } from "./tag";
6
+ import { GitHubTeamManager } from "./team";
6
7
  export class GitHubClient {
7
8
  client;
8
9
  isExplicitToken;
9
10
  tagManager;
10
11
  outputManager;
11
12
  prManager;
13
+ teamManager;
12
14
  constructor(client, isExplicitToken) {
13
15
  this.client = client;
14
16
  this.isExplicitToken = isExplicitToken;
15
17
  this.tagManager = new GitHubTagManager(this.client, this.isExplicitToken);
16
18
  this.outputManager = new GitHubOutputManager();
17
19
  this.prManager = new GitHubPRManager(this.client);
20
+ this.teamManager = new GitHubTeamManager(this.client);
18
21
  }
19
22
  /**
20
23
  * @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
@@ -68,4 +71,10 @@ export class GitHubClient {
68
71
  sendPrMessage(...args) {
69
72
  return this.prManager.sendPrMessage(...args);
70
73
  }
74
+ mergePr(...args) {
75
+ return this.prManager.mergePr(...args);
76
+ }
77
+ isTeamMember(...args) {
78
+ return this.teamManager.isTeamMember(...args);
79
+ }
71
80
  }
@@ -34,6 +34,16 @@ export declare class GitHubPRManager {
34
34
  originRepo: [OwnerString, RepoString];
35
35
  manifestRepo: [OwnerString, RepoString];
36
36
  }): Promise<void>;
37
+ /**
38
+ * @note if the PR doesn't exist yet, just use `updateK8sTagWithPR` instead, since it
39
+ * creates the PR with the necessary changes and merges it for you in one call.
40
+ */
41
+ mergePr({ prId, owner, repository, mergeMethod, }: {
42
+ prId: number;
43
+ owner: string;
44
+ repository: string;
45
+ mergeMethod?: "merge" | "squash" | "rebase";
46
+ }): Promise<void>;
37
47
  sendPrMessage({ prId, owner, repository, message, }: {
38
48
  prId: number;
39
49
  owner: string;
@@ -91,11 +91,22 @@ export class GitHubPRManager {
91
91
  base: baseBranch,
92
92
  body: `Automated image tag change to ${newTag} for ${imageName} in ${environment} triggered by [${originOwner}/${originRepository}](https://github.com/${originOwner}/${originRepository}).`,
93
93
  });
94
- await this.client.rest.pulls.merge({
94
+ await this.mergePr({
95
+ prId: pr.number,
95
96
  owner: manifestOwner,
96
- repo: manifestRepository,
97
- pull_number: pr.number,
98
- merge_method: "squash",
97
+ repository: manifestRepository,
98
+ });
99
+ }
100
+ /**
101
+ * @note if the PR doesn't exist yet, just use `updateK8sTagWithPR` instead, since it
102
+ * creates the PR with the necessary changes and merges it for you in one call.
103
+ */
104
+ async mergePr({ prId, owner, repository, mergeMethod = "squash", }) {
105
+ await this.client.rest.pulls.merge({
106
+ owner,
107
+ repo: repository,
108
+ pull_number: prId,
109
+ merge_method: mergeMethod,
99
110
  });
100
111
  }
101
112
  async sendPrMessage({ prId, owner, repository, message, }) {
@@ -0,0 +1,16 @@
1
+ import type { Octokit } from "@octokit/rest";
2
+ export declare class GitHubTeamManager {
3
+ private readonly client;
4
+ constructor(client: Octokit);
5
+ /**
6
+ * Confirms whether the given user is an active member of a team within an org.
7
+ *
8
+ * @note this only returns `true` for `active` memberships. A user with a `pending`
9
+ * invite (has not accepted yet) will return `false`.
10
+ */
11
+ isTeamMember({ org, teamSlug, username, }: {
12
+ org: string;
13
+ teamSlug: string;
14
+ username: string;
15
+ }): Promise<boolean>;
16
+ }
@@ -0,0 +1,31 @@
1
+ export class GitHubTeamManager {
2
+ client;
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ /**
7
+ * Confirms whether the given user is an active member of a team within an org.
8
+ *
9
+ * @note this only returns `true` for `active` memberships. A user with a `pending`
10
+ * invite (has not accepted yet) will return `false`.
11
+ */
12
+ async isTeamMember({ org, teamSlug, username, }) {
13
+ try {
14
+ const { data } = await this.client.rest.teams.getMembershipForUserInOrg({
15
+ org,
16
+ team_slug: teamSlug,
17
+ username,
18
+ });
19
+ return data.state === "active";
20
+ }
21
+ catch (e) {
22
+ if (e &&
23
+ typeof e === "object" &&
24
+ "status" in e &&
25
+ e.status === 404) {
26
+ return false;
27
+ }
28
+ throw e;
29
+ }
30
+ }
31
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
6
- "version": "1.0.73",
6
+ "version": "1.0.74",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },