Skip to content

Commit 15a127b

Browse files
committed
wip
1 parent fd4a18e commit 15a127b

14 files changed

+1890
-2074
lines changed

index.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import addChannelGitHub from "./lib/add-channel.js";
77
import publishGitHub from "./lib/publish.js";
88
import successGitHub from "./lib/success.js";
99
import failGitHub from "./lib/fail.js";
10-
import { SemanticReleaseOctokit } from "./lib/octokit.js";
10+
import { SemanticReleaseOctokit, getOctokitInstance } from "./lib/octokit.js";
1111

1212
let verified;
13+
let octokit;
1314

1415
export async function verifyConditions(
1516
pluginConfig,
@@ -44,7 +45,9 @@ export async function verifyConditions(
4445
);
4546
}
4647

47-
await verifyGitHub(pluginConfig, context, { Octokit });
48+
octokit = octokit || getOctokitInstance(Octokit, pluginConfig, context);
49+
50+
await verifyGitHub(pluginConfig, context, { octokit });
4851
verified = true;
4952
}
5053

@@ -53,49 +56,57 @@ export async function publish(
5356
context,
5457
{ Octokit = SemanticReleaseOctokit } = {}
5558
) {
59+
octokit = octokit || getOctokitInstance(Octokit, pluginConfig, context);
60+
5661
if (!verified) {
57-
await verifyGitHub(pluginConfig, context, { Octokit });
62+
await verifyGitHub(pluginConfig, context, { octokit });
5863
verified = true;
5964
}
6065

61-
return publishGitHub(pluginConfig, context, { Octokit });
66+
return publishGitHub(pluginConfig, context, { octokit });
6267
}
6368

6469
export async function addChannel(
6570
pluginConfig,
6671
context,
6772
{ Octokit = SemanticReleaseOctokit } = {}
6873
) {
74+
octokit = octokit || getOctokitInstance(Octokit, pluginConfig, context);
75+
6976
if (!verified) {
70-
await verifyGitHub(pluginConfig, context, { Octokit });
77+
await verifyGitHub(pluginConfig, context, { octokit });
7178
verified = true;
7279
}
7380

74-
return addChannelGitHub(pluginConfig, context, { Octokit });
81+
return addChannelGitHub(pluginConfig, context, { octokit });
7582
}
7683

7784
export async function success(
7885
pluginConfig,
7986
context,
8087
{ Octokit = SemanticReleaseOctokit } = {}
8188
) {
89+
octokit = octokit || getOctokitInstance(Octokit, pluginConfig, context);
90+
8291
if (!verified) {
83-
await verifyGitHub(pluginConfig, context, { Octokit });
92+
await verifyGitHub(pluginConfig, context, { octokit });
8493
verified = true;
8594
}
8695

87-
await successGitHub(pluginConfig, context, { Octokit });
96+
await successGitHub(pluginConfig, context, { octokit });
8897
}
8998

9099
export async function fail(
91100
pluginConfig,
92101
context,
93102
{ Octokit = SemanticReleaseOctokit } = {}
94103
) {
104+
octokit = octokit || getOctokitInstance(Octokit, pluginConfig, context);
105+
95106
if (!verified) {
96-
await verifyGitHub(pluginConfig, context, { Octokit });
107+
await verifyGitHub(pluginConfig, context, { octokit });
97108
verified = true;
98109
}
99110

100-
await failGitHub(pluginConfig, context, { Octokit });
111+
await failGitHub(pluginConfig, context, { octokit });
101112
}

lib/add-channel.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,18 @@ import debugFactory from "debug";
22

33
import { RELEASE_NAME } from "./definitions/constants.js";
44
import parseGithubUrl from "./parse-github-url.js";
5-
import resolveConfig from "./resolve-config.js";
65
import isPrerelease from "./is-prerelease.js";
7-
import { toOctokitOptions } from "./octokit.js";
86

97
const debug = debugFactory("semantic-release:github");
108

11-
export default async function addChannel(pluginConfig, context, { Octokit }) {
9+
export default async function addChannel(pluginConfig, context, { octokit }) {
1210
const {
1311
options: { repositoryUrl },
1412
branch,
1513
nextRelease: { name, gitTag, notes },
1614
logger,
1715
} = context;
18-
const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig(
19-
pluginConfig,
20-
context
21-
);
2216
const { owner, repo } = parseGithubUrl(repositoryUrl);
23-
const octokit = new Octokit(
24-
toOctokitOptions({
25-
githubToken,
26-
githubUrl,
27-
githubApiPathPrefix,
28-
proxy,
29-
})
30-
);
3117
let releaseId;
3218

3319
const release = {

lib/fail.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import getFailComment from "./get-fail-comment.js";
1010

1111
const debug = debugFactory("semantic-release:github");
1212

13-
export default async function fail(pluginConfig, context, { Octokit }) {
13+
export default async function fail(pluginConfig, context, { octokit }) {
1414
const {
1515
options: { repositoryUrl },
1616
branch,
@@ -31,9 +31,6 @@ export default async function fail(pluginConfig, context, { Octokit }) {
3131
if (failComment === false || failTitle === false) {
3232
logger.log("Skip issue creation.");
3333
} else {
34-
const octokit = new Octokit(
35-
toOctokitOptions({ githubToken, githubUrl, githubApiPathPrefix, proxy })
36-
);
3734
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
3835
const { data: repoData } = await octokit.request(
3936
"GET /repos/{owner}/{repo}",

lib/octokit.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { HttpsProxyAgent } from "https-proxy-agent";
1717

1818
import { RETRY_CONF } from "./definitions/retry.js";
1919
import { THROTTLE_CONF } from "./definitions/throttle.js";
20+
import resolveConfig from "./resolve-config.js";
2021

2122
// NOTE: replace with import ... assert { type: 'json' } once supported
2223
const require = createRequire(import.meta.url);
@@ -74,3 +75,14 @@ export function toOctokitOptions(options) {
7475
},
7576
};
7677
}
78+
79+
export function getOctokitInstance(Octokit, pluginConfig, context) {
80+
const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig(
81+
pluginConfig,
82+
context
83+
);
84+
85+
return new Octokit(
86+
toOctokitOptions({ githubToken, githubUrl, githubApiPathPrefix, proxy })
87+
);
88+
}

lib/publish.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,20 @@ import { RELEASE_NAME } from "./definitions/constants.js";
99
import parseGithubUrl from "./parse-github-url.js";
1010
import globAssets from "./glob-assets.js";
1111
import resolveConfig from "./resolve-config.js";
12-
import { toOctokitOptions } from "./octokit.js";
1312
import isPrerelease from "./is-prerelease.js";
1413

1514
const debug = debugFactory("semantic-release:github");
1615

17-
export default async function publish(pluginConfig, context, { Octokit }) {
16+
export default async function publish(pluginConfig, context, { octokit }) {
1817
const {
1918
cwd,
2019
options: { repositoryUrl },
2120
branch,
2221
nextRelease: { name, gitTag, notes },
2322
logger,
2423
} = context;
25-
const {
26-
githubToken,
27-
githubUrl,
28-
githubApiPathPrefix,
29-
proxy,
30-
assets,
31-
draftRelease,
32-
} = resolveConfig(pluginConfig, context);
24+
const { assets, draftRelease } = resolveConfig(pluginConfig, context);
3325
const { owner, repo } = parseGithubUrl(repositoryUrl);
34-
const octokit = new Octokit(
35-
toOctokitOptions({
36-
githubToken,
37-
githubUrl,
38-
githubApiPathPrefix,
39-
proxy,
40-
})
41-
);
4226
const release = {
4327
owner,
4428
repo,

lib/success.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import getReleaseLinks from "./get-release-links.js";
1515

1616
const debug = debugFactory("semantic-release:github");
1717

18-
export default async function success(pluginConfig, context, { Octokit }) {
18+
export default async function success(pluginConfig, context, { octokit }) {
1919
const {
2020
options: { repositoryUrl },
2121
commits,
@@ -24,21 +24,14 @@ export default async function success(pluginConfig, context, { Octokit }) {
2424
logger,
2525
} = context;
2626
const {
27-
githubToken,
2827
githubUrl,
29-
githubApiPathPrefix,
30-
proxy,
3128
successComment,
3229
failComment,
3330
failTitle,
3431
releasedLabels,
3532
addReleases,
3633
} = resolveConfig(pluginConfig, context);
3734

38-
const octokit = new Octokit(
39-
toOctokitOptions({ githubToken, githubUrl, githubApiPathPrefix, proxy })
40-
);
41-
4235
// In case the repo changed name, get the new `repo`/`owner` as the search API will not follow redirects
4336
const { data: repoData } = await octokit.request(
4437
"GET /repos/{owner}/{repo}",

lib/verify.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import AggregateError from "aggregate-error";
1111

1212
import parseGithubUrl from "./parse-github-url.js";
1313
import resolveConfig from "./resolve-config.js";
14-
import { toOctokitOptions } from "./octokit.js";
1514
import getError from "./get-error.js";
1615

1716
const isNonEmptyString = (value) => isString(value) && value.trim();
@@ -47,7 +46,7 @@ const VALIDATORS = {
4746
draftRelease: isBoolean,
4847
};
4948

50-
export default async function verify(pluginConfig, context, { Octokit }) {
49+
export default async function verify(pluginConfig, context, { octokit }) {
5150
const {
5251
env,
5352
options: { repositoryUrl },
@@ -83,10 +82,6 @@ export default async function verify(pluginConfig, context, { Octokit }) {
8382
githubToken &&
8483
!errors.find(({ code }) => code === "EINVALIDPROXY")
8584
) {
86-
const octokit = new Octokit(
87-
toOctokitOptions({ githubToken, githubUrl, githubApiPathPrefix, proxy })
88-
);
89-
9085
// https://github.com/semantic-release/github/issues/182
9186
// Do not check for permissions in GitHub actions, as the provided token is an installation access token.
9287
// octokit.request("GET /repos/{owner}/{repo}", {repo, owner}) does not return the "permissions" key in that case.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy