Skip to content

Commit

Permalink
Merge pull request #10 from n0th1ng-else/examples
Browse files Browse the repository at this point in the history
  • Loading branch information
n0th1ng-else committed Nov 17, 2021
2 parents 33b1c9f + e49f1a1 commit e8d1e72
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ The plugin can be configured in the [**semantic-release** configuration file](ht

## Strategy

### Github strategy (`{strategy: 'github'}`)
### GitHub strategy (`{strategy: 'github'}`)

- In case of a single commit in the branch, semantic-release analyzes that commit.
- When multiple commits are in the branch, semantic-release analyzes the commit made of the pull request title and commit concatenation in the body.
Once PR is merged, GitHib creates a squash commit in the main branch following the rules below:

| Number of commits in the pull request | Main Branch Commit Title | Main Branch Commit Description |
| ------------------------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- |
| Single commit | The title of the commit message for the single commit, followed by the pull request number | The body text of the commit message for the single commit |
| More than one commit | The pull request title, followed by the pull request number | A list of the commit messages for all of the squashed commits, in date order |

You can read more about this in the official
[GitHub docs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#merge-message-for-a-squash-merge).
This plugin hijacks semantic-release flow and replaces the commits list with the one that respects these rules
into the mix.

### Pull Request strategy (`{strategy: 'pull-request'}`)

Expand All @@ -66,3 +75,7 @@ The pull request number. In the context of GitHub actions, it is achievable as `

Repository path, for example `n0th1ng-else/semantic-release-pr-analyzer`. For GitHub actions workflow it is
set automatically.

## Examples

##### You can see the sample configuration in the [examples folder](https://github.com/n0th1ng-else/semantic-release-pr-analyzer/tree/main/examples).
22 changes: 22 additions & 0 deletions examples/release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const getConfig = (runInPRContext) => {
// In the pull-request action we only use semantic-release-pr-analyzer plugin
if (runInPRContext) {
return {
plugins: ["semantic-release-pr-analyzer"],
};
}

// Default configuration for the real release workflow
return {
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
],
};
};

const runInPRContext = Boolean(process.env.GITHUB_PR_NUMBER);

module.exports = getConfig(runInPRContext);
11 changes: 10 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const STRATEGY = {
StrictPullRequest: "strict-pull-request",
};

const getCommit = async (strategy, commits) => {
const getRawCommit = async (strategy, commits) => {
switch (strategy) {
case STRATEGY.Github:
return getGithubStrategyCommit(commits);
Expand All @@ -94,6 +94,15 @@ const getCommit = async (strategy, commits) => {
}
};

const getCommit = async (strategy, commits) => {
/**
* TODO add pull-request number to the commit title.
* This does not affect the expected version.
* Just for consistency with GitHub.
*/
return getRawCommit(strategy, commits);
};

const validateStrategy = (strategy) => {
if (!strategy) {
return STRATEGY.Github;
Expand Down

0 comments on commit e8d1e72

Please sign in to comment.