Skip to content

Commit

Permalink
Merge pull request #18 from n0th1ng-else/debug
Browse files Browse the repository at this point in the history
  • Loading branch information
n0th1ng-else authored Jan 14, 2022
2 parents 6ae26a8 + ebbcd9d commit a604e67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"conventional-changelog-writer": "^4.0.0",
"conventional-commits-filter": "^2.0.0",
"conventional-commits-parser": "^3.0.0",
"debug": "^4.3.3",
"get-stream": "^6.0.0",
"into-stream": "^6.0.0"
},
Expand Down
19 changes: 15 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Octokit } = require("@octokit/rest");
const debug = require("debug")("semantic-release:pr-analyzer");

const getEnv = () => {
const {
Expand Down Expand Up @@ -26,10 +27,17 @@ const getEnv = () => {
};
};

const eqSubject = (commit1, commit2) => commit1.subject === commit2.subject;
const eqSubject = (commit1, commit2) => {
debug(`commit 1 subject was ${commit1.subject}`);
debug(`commit 2 subject was ${commit2.subject}`);
return commit1.subject === commit2.subject;
};

const eqFull = (commit1, commit2) =>
eqSubject(commit1, commit2) && commit1.body === commit2.body;
const eqFull = (commit1, commit2) => {
debug(`commit 1 body was ${commit1.body}`);
debug(`commit 2 body was ${commit2.body}`);
return eqSubject(commit1, commit2) && commit1.body === commit2.body;
};

const mergeItems = (arr) => arr.join("\n\n");

Expand Down Expand Up @@ -69,12 +77,13 @@ const getGithubStrategyCommitBody = (commits) =>

const getGithubStrategyCommit = async (commits, prCommit) => {
if (commits.length === 1) {
debug("Only single commit found, using it");
return getFirstCommit(commits);
}

const { subject } = prCommit || (await getPullRequestAsCommit());
const body = getGithubStrategyCommitBody(commits);

debug("Using the pull request message as a commit");
return imitateCommit(subject, body);
};

Expand Down Expand Up @@ -147,10 +156,12 @@ const getStrategies = () => Object.values(STRATEGY);

const validateStrategy = (strategy) => {
if (!strategy) {
debug(`Using strategy: ${STRATEGY.Github}`);
return STRATEGY.Github;
}

if (Object.values(STRATEGY).includes(strategy)) {
debug(`Using strategy: ${strategy}`);
return strategy;
}

Expand Down

0 comments on commit a604e67

Please sign in to comment.