Skip to content

Commit

Permalink
Merge pull request #15 from n0th1ng-else/cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
n0th1ng-else committed Nov 18, 2021
2 parents 8632610 + 3b90699 commit e7a8e7f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Use of the semantic-release-pr-analyzer with default parameters

const getConfig = (runInPRContext) => {
// In the pull-request action we only use semantic-release-pr-analyzer plugin
if (runInPRContext) {
Expand Down
38 changes: 38 additions & 0 deletions examples/release.config.parametrized.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Use of the semantic-release-pr-analyzer with pull-request strategy.
// Also we can override the defaults for commit-analyzer and release-notes-generator

const getConfig = (runInPRContext) => {
// In the pull-request action we only use semantic-release-pr-analyzer plugin
if (runInPRContext) {
return {
plugins: [
[
"semantic-release-pr-analyzer",
{
strategy: "pull-request",
commitAnalyzerConfig: {
preset: "eslint",
},
notesGeneratorConfig: {
preset: "eslint",
},
},
],
],
};
}

// 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);
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ const { validateStrategy } = require("./src/utils");

const analyzeCommits = async (pluginConfig, context) => {
const { commitAnalyzerConfig, strategy: strtg } = pluginConfig || {};

const strategy = validateStrategy(strtg);

return ac(strategy, commitAnalyzerConfig, context);
return ac(strategy, { ...pluginConfig, ...commitAnalyzerConfig }, context);
};

const generateNotes = async (pluginConfig, context) => {
const { notesGeneratorConfig, strategy: strtg } = pluginConfig || {};

const strategy = validateStrategy(strtg);

return gn(strategy, notesGeneratorConfig, context);
return gn(strategy, { ...pluginConfig, ...notesGeneratorConfig }, context);
};

module.exports = { generateNotes, analyzeCommits };
46 changes: 44 additions & 2 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("analyzeCommits", () => {

it("works when there is no plugin config specified, defaults to github strategy", () => {
return analyzeCommits().then(() => {
expect(ac).toBeCalledWith("github", undefined, undefined);
expect(ac).toBeCalledWith("github", {}, undefined);
});
});

Expand All @@ -34,6 +34,27 @@ describe("analyzeCommits", () => {
}
);
});

it("should pass the whole config down to the commit-analyzer", () => {
const cfg = { foo: "bar" };
return analyzeCommits(cfg).then(() => {
expect(ac).toBeCalledWith("github", cfg, undefined);
});
});

it("should enrich the custom configuration for commit-analyzer", () => {
const cfg = { foo: "bar", commitAnalyzerConfig: { baz: "feed" } };
return analyzeCommits(cfg).then(() => {
expect(ac).toBeCalledWith("github", { ...cfg, baz: "feed" }, undefined);
});
});

it("should override default configuration for commit-analyzer", () => {
const cfg = { foo: "bar", commitAnalyzerConfig: { foo: "baz" } };
return analyzeCommits(cfg).then(() => {
expect(ac).toBeCalledWith("github", { ...cfg, foo: "baz" }, undefined);
});
});
});

describe("generateNotes", () => {
Expand All @@ -43,7 +64,7 @@ describe("generateNotes", () => {

it("works when there is no plugin config specified, defaults to github strategy", () => {
return generateNotes().then(() => {
expect(gn).toBeCalledWith("github", undefined, undefined);
expect(gn).toBeCalledWith("github", {}, undefined);
});
});

Expand All @@ -60,4 +81,25 @@ describe("generateNotes", () => {
}
);
});

it("should pass the whole config down to the release-notes-generator", () => {
const cfg = { foo: "bar" };
return generateNotes(cfg).then(() => {
expect(gn).toBeCalledWith("github", cfg, undefined);
});
});

it("should enrich the custom configuration for release-notes-generator", () => {
const cfg = { foo: "bar", notesGeneratorConfig: { baz: "feed" } };
return generateNotes(cfg).then(() => {
expect(gn).toBeCalledWith("github", { ...cfg, baz: "feed" }, undefined);
});
});

it("should override default configuration for release-notes-generator", () => {
const cfg = { foo: "bar", notesGeneratorConfig: { foo: "baz" } };
return generateNotes(cfg).then(() => {
expect(gn).toBeCalledWith("github", { ...cfg, foo: "baz" }, undefined);
});
});
});

0 comments on commit e7a8e7f

Please sign in to comment.