Skip to content

Commit 1eaede2

Browse files
authored
feat: ES Module (#419)
BREAKING CHANGE: `@semantic-release/github` is now a native ES Module
1 parent 3dc59ec commit 1eaede2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+14608
-13632
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- '14.17'
17-
- 16
16+
- 18.0.0
17+
- 19
18+
- 20
1819
os:
1920
- ubuntu-latest
2021
runs-on: "${{ matrix.os }}"
@@ -25,19 +26,22 @@ jobs:
2526
with:
2627
node-version: "${{ matrix.node-version }}"
2728
cache: npm
28-
- run: npm ci
29-
- run: "npm run test:ci"
29+
- run: npm clean-install
30+
- run: npm test
3031
test:
3132
runs-on: ubuntu-latest
3233
needs: test_matrix
3334
steps:
3435
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
3536
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
3637
with:
37-
node-version: 16
38+
node-version: "lts/*"
3839
cache: npm
39-
- run: npm ci
40+
- run: npm clean-install
41+
- run: npm audit signatures
4042
- name: Ensure dependencies are compatible with the version of node
4143
run: npx ls-engines
4244
- run: npm run lint
43-
- run: npx lockfile-lint --path package-lock.json
45+
# https://github.com/lirantal/lockfile-lint#readme
46+
- name: Scan lockfile for security issues
47+
run: npx lockfile-lint --path package-lock.json

README.md

Lines changed: 30 additions & 27 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,101 @@
11
/* eslint require-atomic-updates: off */
22

3-
const {defaultTo, castArray} = require('lodash');
4-
const verifyGitHub = require('./lib/verify');
5-
const addChannelGitHub = require('./lib/add-channel');
6-
const publishGitHub = require('./lib/publish');
7-
const successGitHub = require('./lib/success');
8-
const failGitHub = require('./lib/fail');
3+
import { defaultTo, castArray } from "lodash-es";
4+
5+
import verifyGitHub from "./lib/verify.js";
6+
import addChannelGitHub from "./lib/add-channel.js";
7+
import publishGitHub from "./lib/publish.js";
8+
import successGitHub from "./lib/success.js";
9+
import failGitHub from "./lib/fail.js";
10+
import { SemanticReleaseOctokit } from "./lib/octokit.js";
911

1012
let verified;
1113

12-
async function verifyConditions(pluginConfig, context) {
13-
const {options} = context;
14+
export async function verifyConditions(
15+
pluginConfig,
16+
context,
17+
{ Octokit = SemanticReleaseOctokit } = {}
18+
) {
19+
const { options } = context;
1420
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
1521
if (options.publish) {
1622
const publishPlugin =
17-
castArray(options.publish).find((config) => config.path && config.path === '@semantic-release/github') || {};
23+
castArray(options.publish).find(
24+
(config) => config.path && config.path === "@semantic-release/github"
25+
) || {};
1826

1927
pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets);
20-
pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment);
21-
pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment);
22-
pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle);
28+
pluginConfig.successComment = defaultTo(
29+
pluginConfig.successComment,
30+
publishPlugin.successComment
31+
);
32+
pluginConfig.failComment = defaultTo(
33+
pluginConfig.failComment,
34+
publishPlugin.failComment
35+
);
36+
pluginConfig.failTitle = defaultTo(
37+
pluginConfig.failTitle,
38+
publishPlugin.failTitle
39+
);
2340
pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels);
24-
pluginConfig.assignees = defaultTo(pluginConfig.assignees, publishPlugin.assignees);
41+
pluginConfig.assignees = defaultTo(
42+
pluginConfig.assignees,
43+
publishPlugin.assignees
44+
);
2545
}
2646

27-
await verifyGitHub(pluginConfig, context);
47+
await verifyGitHub(pluginConfig, context, { Octokit });
2848
verified = true;
2949
}
3050

31-
async function publish(pluginConfig, context) {
51+
export async function publish(
52+
pluginConfig,
53+
context,
54+
{ Octokit = SemanticReleaseOctokit } = {}
55+
) {
3256
if (!verified) {
33-
await verifyGitHub(pluginConfig, context);
57+
await verifyGitHub(pluginConfig, context, { Octokit });
3458
verified = true;
3559
}
3660

37-
return publishGitHub(pluginConfig, context);
61+
return publishGitHub(pluginConfig, context, { Octokit });
3862
}
3963

40-
async function addChannel(pluginConfig, context) {
64+
export async function addChannel(
65+
pluginConfig,
66+
context,
67+
{ Octokit = SemanticReleaseOctokit } = {}
68+
) {
4169
if (!verified) {
42-
await verifyGitHub(pluginConfig, context);
70+
await verifyGitHub(pluginConfig, context, { Octokit });
4371
verified = true;
4472
}
4573

46-
return addChannelGitHub(pluginConfig, context);
74+
return addChannelGitHub(pluginConfig, context, { Octokit });
4775
}
4876

49-
async function success(pluginConfig, context) {
77+
export async function success(
78+
pluginConfig,
79+
context,
80+
{ Octokit = SemanticReleaseOctokit } = {}
81+
) {
5082
if (!verified) {
51-
await verifyGitHub(pluginConfig, context);
83+
await verifyGitHub(pluginConfig, context, { Octokit });
5284
verified = true;
5385
}
5486

55-
await successGitHub(pluginConfig, context);
87+
await successGitHub(pluginConfig, context, { Octokit });
5688
}
5789

58-
async function fail(pluginConfig, context) {
90+
export async function fail(
91+
pluginConfig,
92+
context,
93+
{ Octokit = SemanticReleaseOctokit } = {}
94+
) {
5995
if (!verified) {
60-
await verifyGitHub(pluginConfig, context);
96+
await verifyGitHub(pluginConfig, context, { Octokit });
6197
verified = true;
6298
}
6399

64-
await failGitHub(pluginConfig, context);
100+
await failGitHub(pluginConfig, context, { Octokit });
65101
}
66-
67-
module.exports = {verifyConditions, addChannel, publish, success, fail};

lib/add-channel.js

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,81 @@
1-
const debug = require('debug')('semantic-release:github');
2-
const {RELEASE_NAME} = require('./definitions/constants');
3-
const parseGithubUrl = require('./parse-github-url');
4-
const resolveConfig = require('./resolve-config');
5-
const getClient = require('./get-client');
6-
const isPrerelease = require('./is-prerelease');
7-
8-
module.exports = async (pluginConfig, context) => {
1+
import debugFactory from "debug";
2+
3+
import { RELEASE_NAME } from "./definitions/constants.js";
4+
import parseGithubUrl from "./parse-github-url.js";
5+
import resolveConfig from "./resolve-config.js";
6+
import isPrerelease from "./is-prerelease.js";
7+
import { toOctokitOptions, SemanticReleaseOctokit } from "./octokit.js";
8+
9+
const debug = debugFactory("semantic-release:github");
10+
11+
export default async function addChannel(pluginConfig, context, { Octokit }) {
912
const {
10-
options: {repositoryUrl},
13+
options: { repositoryUrl },
1114
branch,
12-
nextRelease: {name, gitTag, notes},
15+
nextRelease: { name, gitTag, notes },
1316
logger,
1417
} = context;
15-
const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context);
16-
const {owner, repo} = parseGithubUrl(repositoryUrl);
17-
const octokit = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
18+
const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig(
19+
pluginConfig,
20+
context
21+
);
22+
const { owner, repo } = parseGithubUrl(repositoryUrl);
23+
const octokit = new Octokit(
24+
toOctokitOptions({
25+
githubToken,
26+
githubUrl,
27+
githubApiPathPrefix,
28+
proxy,
29+
})
30+
);
1831
let releaseId;
1932

20-
const release = {owner, repo, name, prerelease: isPrerelease(branch), tag_name: gitTag};
33+
const release = {
34+
owner,
35+
repo,
36+
name,
37+
prerelease: isPrerelease(branch),
38+
tag_name: gitTag,
39+
};
2140

22-
debug('release object: %O', release);
41+
debug("release object: %O", release);
2342

2443
try {
2544
({
26-
data: {id: releaseId},
27-
} = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {owner, repo, tag: gitTag}));
45+
data: { id: releaseId },
46+
} = await octokit.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", {
47+
owner,
48+
repo,
49+
tag: gitTag,
50+
}));
2851
} catch (error) {
2952
if (error.status === 404) {
30-
logger.log('There is no release for tag %s, creating a new one', gitTag);
53+
logger.log("There is no release for tag %s, creating a new one", gitTag);
3154

3255
const {
33-
data: {html_url: url},
34-
} = await octokit.request('POST /repos/{owner}/{repo}/releases', {...release, body: notes});
56+
data: { html_url: url },
57+
} = await octokit.request("POST /repos/{owner}/{repo}/releases", {
58+
...release,
59+
body: notes,
60+
});
3561

36-
logger.log('Published GitHub release: %s', url);
37-
return {url, name: RELEASE_NAME};
62+
logger.log("Published GitHub release: %s", url);
63+
return { url, name: RELEASE_NAME };
3864
}
3965

4066
throw error;
4167
}
4268

43-
debug('release release_id: %o', releaseId);
69+
debug("release release_id: %o", releaseId);
4470

4571
const {
46-
data: {html_url: url},
47-
} = await octokit.request('PATCH /repos/{owner}/{repo}/releases/{release_id}', {...release, release_id: releaseId});
72+
data: { html_url: url },
73+
} = await octokit.request(
74+
"PATCH /repos/{owner}/{repo}/releases/{release_id}",
75+
{ ...release, release_id: releaseId }
76+
);
4877

49-
logger.log('Updated GitHub release: %s', url);
78+
logger.log("Updated GitHub release: %s", url);
5079

51-
return {url, name: RELEASE_NAME};
52-
};
80+
return { url, name: RELEASE_NAME };
81+
}

lib/definitions/constants.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const ISSUE_ID = '<!-- semantic-release:github -->';
1+
export const ISSUE_ID = "<!-- semantic-release:github -->";
22

3-
const RELEASE_NAME = 'GitHub release';
4-
5-
module.exports = {ISSUE_ID, RELEASE_NAME};
3+
export const RELEASE_NAME = "GitHub release";

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