-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: `@semantic-release/github` is now a native ES Module
- Loading branch information
Showing
43 changed files
with
14,608 additions
and
13,632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,101 @@ | ||
/* eslint require-atomic-updates: off */ | ||
|
||
const {defaultTo, castArray} = require('lodash'); | ||
const verifyGitHub = require('./lib/verify'); | ||
const addChannelGitHub = require('./lib/add-channel'); | ||
const publishGitHub = require('./lib/publish'); | ||
const successGitHub = require('./lib/success'); | ||
const failGitHub = require('./lib/fail'); | ||
import { defaultTo, castArray } from "lodash-es"; | ||
|
||
import verifyGitHub from "./lib/verify.js"; | ||
import addChannelGitHub from "./lib/add-channel.js"; | ||
import publishGitHub from "./lib/publish.js"; | ||
import successGitHub from "./lib/success.js"; | ||
import failGitHub from "./lib/fail.js"; | ||
import { SemanticReleaseOctokit } from "./lib/octokit.js"; | ||
|
||
let verified; | ||
|
||
async function verifyConditions(pluginConfig, context) { | ||
const {options} = context; | ||
export async function verifyConditions( | ||
pluginConfig, | ||
context, | ||
{ Octokit = SemanticReleaseOctokit } = {} | ||
) { | ||
const { options } = context; | ||
// 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 | ||
if (options.publish) { | ||
const publishPlugin = | ||
castArray(options.publish).find((config) => config.path && config.path === '@semantic-release/github') || {}; | ||
castArray(options.publish).find( | ||
(config) => config.path && config.path === "@semantic-release/github" | ||
) || {}; | ||
|
||
pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets); | ||
pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment); | ||
pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment); | ||
pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle); | ||
pluginConfig.successComment = defaultTo( | ||
pluginConfig.successComment, | ||
publishPlugin.successComment | ||
); | ||
pluginConfig.failComment = defaultTo( | ||
pluginConfig.failComment, | ||
publishPlugin.failComment | ||
); | ||
pluginConfig.failTitle = defaultTo( | ||
pluginConfig.failTitle, | ||
publishPlugin.failTitle | ||
); | ||
pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels); | ||
pluginConfig.assignees = defaultTo(pluginConfig.assignees, publishPlugin.assignees); | ||
pluginConfig.assignees = defaultTo( | ||
pluginConfig.assignees, | ||
publishPlugin.assignees | ||
); | ||
} | ||
|
||
await verifyGitHub(pluginConfig, context); | ||
await verifyGitHub(pluginConfig, context, { Octokit }); | ||
verified = true; | ||
} | ||
|
||
async function publish(pluginConfig, context) { | ||
export async function publish( | ||
pluginConfig, | ||
context, | ||
{ Octokit = SemanticReleaseOctokit } = {} | ||
) { | ||
if (!verified) { | ||
await verifyGitHub(pluginConfig, context); | ||
await verifyGitHub(pluginConfig, context, { Octokit }); | ||
verified = true; | ||
} | ||
|
||
return publishGitHub(pluginConfig, context); | ||
return publishGitHub(pluginConfig, context, { Octokit }); | ||
} | ||
|
||
async function addChannel(pluginConfig, context) { | ||
export async function addChannel( | ||
pluginConfig, | ||
context, | ||
{ Octokit = SemanticReleaseOctokit } = {} | ||
) { | ||
if (!verified) { | ||
await verifyGitHub(pluginConfig, context); | ||
await verifyGitHub(pluginConfig, context, { Octokit }); | ||
verified = true; | ||
} | ||
|
||
return addChannelGitHub(pluginConfig, context); | ||
return addChannelGitHub(pluginConfig, context, { Octokit }); | ||
} | ||
|
||
async function success(pluginConfig, context) { | ||
export async function success( | ||
pluginConfig, | ||
context, | ||
{ Octokit = SemanticReleaseOctokit } = {} | ||
) { | ||
if (!verified) { | ||
await verifyGitHub(pluginConfig, context); | ||
await verifyGitHub(pluginConfig, context, { Octokit }); | ||
verified = true; | ||
} | ||
|
||
await successGitHub(pluginConfig, context); | ||
await successGitHub(pluginConfig, context, { Octokit }); | ||
} | ||
|
||
async function fail(pluginConfig, context) { | ||
export async function fail( | ||
pluginConfig, | ||
context, | ||
{ Octokit = SemanticReleaseOctokit } = {} | ||
) { | ||
if (!verified) { | ||
await verifyGitHub(pluginConfig, context); | ||
await verifyGitHub(pluginConfig, context, { Octokit }); | ||
verified = true; | ||
} | ||
|
||
await failGitHub(pluginConfig, context); | ||
await failGitHub(pluginConfig, context, { Octokit }); | ||
} | ||
|
||
module.exports = {verifyConditions, addChannel, publish, success, fail}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,81 @@ | ||
const debug = require('debug')('semantic-release:github'); | ||
const {RELEASE_NAME} = require('./definitions/constants'); | ||
const parseGithubUrl = require('./parse-github-url'); | ||
const resolveConfig = require('./resolve-config'); | ||
const getClient = require('./get-client'); | ||
const isPrerelease = require('./is-prerelease'); | ||
|
||
module.exports = async (pluginConfig, context) => { | ||
import debugFactory from "debug"; | ||
|
||
import { RELEASE_NAME } from "./definitions/constants.js"; | ||
import parseGithubUrl from "./parse-github-url.js"; | ||
import resolveConfig from "./resolve-config.js"; | ||
import isPrerelease from "./is-prerelease.js"; | ||
import { toOctokitOptions, SemanticReleaseOctokit } from "./octokit.js"; | ||
|
||
const debug = debugFactory("semantic-release:github"); | ||
|
||
export default async function addChannel(pluginConfig, context, { Octokit }) { | ||
const { | ||
options: {repositoryUrl}, | ||
options: { repositoryUrl }, | ||
branch, | ||
nextRelease: {name, gitTag, notes}, | ||
nextRelease: { name, gitTag, notes }, | ||
logger, | ||
} = context; | ||
const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context); | ||
const {owner, repo} = parseGithubUrl(repositoryUrl); | ||
const octokit = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy}); | ||
const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig( | ||
pluginConfig, | ||
context | ||
); | ||
const { owner, repo } = parseGithubUrl(repositoryUrl); | ||
const octokit = new Octokit( | ||
toOctokitOptions({ | ||
githubToken, | ||
githubUrl, | ||
githubApiPathPrefix, | ||
proxy, | ||
}) | ||
); | ||
let releaseId; | ||
|
||
const release = {owner, repo, name, prerelease: isPrerelease(branch), tag_name: gitTag}; | ||
const release = { | ||
owner, | ||
repo, | ||
name, | ||
prerelease: isPrerelease(branch), | ||
tag_name: gitTag, | ||
}; | ||
|
||
debug('release object: %O', release); | ||
debug("release object: %O", release); | ||
|
||
try { | ||
({ | ||
data: {id: releaseId}, | ||
} = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {owner, repo, tag: gitTag})); | ||
data: { id: releaseId }, | ||
} = await octokit.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", { | ||
owner, | ||
repo, | ||
tag: gitTag, | ||
})); | ||
} catch (error) { | ||
if (error.status === 404) { | ||
logger.log('There is no release for tag %s, creating a new one', gitTag); | ||
logger.log("There is no release for tag %s, creating a new one", gitTag); | ||
|
||
const { | ||
data: {html_url: url}, | ||
} = await octokit.request('POST /repos/{owner}/{repo}/releases', {...release, body: notes}); | ||
data: { html_url: url }, | ||
} = await octokit.request("POST /repos/{owner}/{repo}/releases", { | ||
...release, | ||
body: notes, | ||
}); | ||
|
||
logger.log('Published GitHub release: %s', url); | ||
return {url, name: RELEASE_NAME}; | ||
logger.log("Published GitHub release: %s", url); | ||
return { url, name: RELEASE_NAME }; | ||
} | ||
|
||
throw error; | ||
} | ||
|
||
debug('release release_id: %o', releaseId); | ||
debug("release release_id: %o", releaseId); | ||
|
||
const { | ||
data: {html_url: url}, | ||
} = await octokit.request('PATCH /repos/{owner}/{repo}/releases/{release_id}', {...release, release_id: releaseId}); | ||
data: { html_url: url }, | ||
} = await octokit.request( | ||
"PATCH /repos/{owner}/{repo}/releases/{release_id}", | ||
{ ...release, release_id: releaseId } | ||
); | ||
|
||
logger.log('Updated GitHub release: %s', url); | ||
logger.log("Updated GitHub release: %s", url); | ||
|
||
return {url, name: RELEASE_NAME}; | ||
}; | ||
return { url, name: RELEASE_NAME }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const ISSUE_ID = '<!-- semantic-release:github -->'; | ||
export const ISSUE_ID = "<!-- semantic-release:github -->"; | ||
|
||
const RELEASE_NAME = 'GitHub release'; | ||
|
||
module.exports = {ISSUE_ID, RELEASE_NAME}; | ||
export const RELEASE_NAME = "GitHub release"; |
Oops, something went wrong.