@tahminator/pipeline 1.0.73-beta.27d4efec → 1.0.73-beta.35856f4d

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,14 +1,12 @@
1
1
  import { GitHubOutputManager } from "./output";
2
2
  import { GitHubPRManager } from "./pr";
3
3
  import { GitHubTagManager } from "./tag";
4
- import { GitHubTeamManager } from "./team";
5
4
  export declare class GitHubClient {
6
5
  private readonly client;
7
6
  private readonly isExplicitToken;
8
7
  private readonly tagManager;
9
8
  private readonly outputManager;
10
9
  private readonly prManager;
11
- private readonly teamManager;
12
10
  private constructor();
13
11
  /**
14
12
  * @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
@@ -41,6 +39,5 @@ export declare class GitHubClient {
41
39
  outputToGithubOutput(...args: Parameters<GitHubOutputManager["outputToGithubOutput"]>): Promise<void>;
42
40
  updateK8sTagWithPR(...args: Parameters<GitHubPRManager["updateK8sTagWithPR"]>): Promise<void>;
43
41
  sendPrMessage(...args: Parameters<GitHubPRManager["sendPrMessage"]>): Promise<void>;
44
- mergePr(...args: Parameters<GitHubPRManager["mergePr"]>): Promise<void>;
45
- isTeamMember(...args: Parameters<GitHubTeamManager["isTeamMember"]>): Promise<boolean>;
42
+ approvePr(...args: Parameters<GitHubPRManager["approvePr"]>): Promise<void>;
46
43
  }
package/dist/gh/client.js CHANGED
@@ -3,21 +3,18 @@ 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";
7
6
  export class GitHubClient {
8
7
  client;
9
8
  isExplicitToken;
10
9
  tagManager;
11
10
  outputManager;
12
11
  prManager;
13
- teamManager;
14
12
  constructor(client, isExplicitToken) {
15
13
  this.client = client;
16
14
  this.isExplicitToken = isExplicitToken;
17
15
  this.tagManager = new GitHubTagManager(this.client, this.isExplicitToken);
18
16
  this.outputManager = new GitHubOutputManager();
19
- this.prManager = new GitHubPRManager(this.client);
20
- this.teamManager = new GitHubTeamManager(this.client);
17
+ this.prManager = new GitHubPRManager(this.client, this.isExplicitToken);
21
18
  }
22
19
  /**
23
20
  * @note `appId` can be `Client ID` or `App ID`. Hover over `appId` for more details.
@@ -71,10 +68,7 @@ export class GitHubClient {
71
68
  sendPrMessage(...args) {
72
69
  return this.prManager.sendPrMessage(...args);
73
70
  }
74
- mergePr(...args) {
75
- return this.prManager.mergePr(...args);
76
- }
77
- isTeamMember(...args) {
78
- return this.teamManager.isTeamMember(...args);
71
+ approvePr(...args) {
72
+ return this.prManager.approvePr(...args);
79
73
  }
80
74
  }
@@ -2,7 +2,9 @@ import type { Octokit } from "@octokit/rest";
2
2
  import type { Environment, OwnerString, RepoString } from "../../types";
3
3
  export declare class GitHubPRManager {
4
4
  private readonly client;
5
- constructor(client: Octokit);
5
+ private readonly isExplicitToken;
6
+ constructor(client: Octokit, isExplicitToken: boolean);
7
+ private checkToken;
6
8
  /**
7
9
  *
8
10
  * update k8s manifest repo with new tag version.
@@ -34,20 +36,23 @@ export declare class GitHubPRManager {
34
36
  originRepo: [OwnerString, RepoString];
35
37
  manifestRepo: [OwnerString, RepoString];
36
38
  }): 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, }: {
39
+ sendPrMessage({ prId, owner, repository, message, }: {
42
40
  prId: number;
43
41
  owner: string;
44
42
  repository: string;
45
- mergeMethod?: "merge" | "squash" | "rebase";
43
+ message: string;
46
44
  }): Promise<void>;
47
- sendPrMessage({ prId, owner, repository, message, }: {
45
+ /**
46
+ * Approves the given pull request.
47
+ *
48
+ * @note requires a token belonging to a user/app distinct from the PR author,
49
+ * since GitHub does not allow self-approval. As such, it is highly recommended to
50
+ * just use an app identity instead.
51
+ */
52
+ approvePr({ prId, owner, repository, message, }: {
48
53
  prId: number;
49
54
  owner: string;
50
55
  repository: string;
51
- message: string;
56
+ message?: string;
52
57
  }): Promise<void>;
53
58
  }
@@ -3,8 +3,15 @@ import { Utils } from "../../utils";
3
3
  import { kustomizeSchema } from "./schema";
4
4
  export class GitHubPRManager {
5
5
  client;
6
- constructor(client) {
6
+ isExplicitToken;
7
+ constructor(client, isExplicitToken) {
7
8
  this.client = client;
9
+ this.isExplicitToken = isExplicitToken;
10
+ }
11
+ checkToken() {
12
+ if (!this.isExplicitToken) {
13
+ throw new Error("You must pass in an explicit GitHub token for this operation. You may either use a PAT or a GitHub App Token");
14
+ }
8
15
  }
9
16
  /**
10
17
  *
@@ -91,29 +98,35 @@ export class GitHubPRManager {
91
98
  base: baseBranch,
92
99
  body: `Automated image tag change to ${newTag} for ${imageName} in ${environment} triggered by [${originOwner}/${originRepository}](https://github.com/${originOwner}/${originRepository}).`,
93
100
  });
94
- await this.mergePr({
95
- prId: pr.number,
101
+ await this.client.rest.pulls.merge({
96
102
  owner: manifestOwner,
97
- repository: manifestRepository,
103
+ repo: manifestRepository,
104
+ pull_number: pr.number,
105
+ merge_method: "squash",
98
106
  });
99
107
  }
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({
108
+ async sendPrMessage({ prId, owner, repository, message, }) {
109
+ await this.client.rest.issues.createComment({
110
+ issue_number: prId,
106
111
  owner,
107
112
  repo: repository,
108
- pull_number: prId,
109
- merge_method: mergeMethod,
113
+ body: message,
110
114
  });
111
115
  }
112
- async sendPrMessage({ prId, owner, repository, message, }) {
113
- await this.client.rest.issues.createComment({
114
- issue_number: prId,
116
+ /**
117
+ * Approves the given pull request.
118
+ *
119
+ * @note requires a token belonging to a user/app distinct from the PR author,
120
+ * since GitHub does not allow self-approval. As such, it is highly recommended to
121
+ * just use an app identity instead.
122
+ */
123
+ async approvePr({ prId, owner, repository, message, }) {
124
+ this.checkToken();
125
+ await this.client.rest.pulls.createReview({
126
+ pull_number: prId,
115
127
  owner,
116
128
  repo: repository,
129
+ event: "APPROVE",
117
130
  body: message,
118
131
  });
119
132
  }
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-beta.27d4efec",
6
+ "version": "1.0.73-beta.35856f4d",
7
7
  "repository": {
8
8
  "url": "git+https://github.com/tahminator/pipeline.git"
9
9
  },
@@ -1,16 +0,0 @@
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
- }
@@ -1,31 +0,0 @@
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
- }