-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from 123FLO321/beta
add support for job parameters
- Loading branch information
Showing
11 changed files
with
227 additions
and
65 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { buildJobParameters } from "./build-job-parameters"; | ||
import { getContext } from "./get-context.spec"; | ||
|
||
describe("build-job-parameters", () => { | ||
it("should correctly build parameters", () => { | ||
const context = getContext(); | ||
expect(buildJobParameters({}, context)).toEqual([]); | ||
expect(buildJobParameters({ test: "test" }, context)).toEqual([{ name: "test", value: "test" }]); | ||
expect(buildJobParameters({ test: "test", hello: "world" }, context)).toEqual([ | ||
{ name: "test", value: "test" }, | ||
{ name: "hello", value: "world" } | ||
]); | ||
expect(buildJobParameters({ version: "{{nextRelease.version}}" }, context)).toEqual([{ name: "version", value: "1.0.0" }]); | ||
expect(buildJobParameters({ channel: "{{#if nextRelease.channel}}{{nextRelease.channel}}{{else}}latest{{/if}}" }, context)).toEqual([ | ||
{ name: "channel", value: "test" } | ||
]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Handlebars from "handlebars"; | ||
import { JobParameter } from "jetbrains-space-api"; | ||
|
||
import { PluginContext } from "../types/plugin-context"; | ||
|
||
/** | ||
* Builds the job parameters and adds the release information. | ||
* @param params The job parameters from the config. | ||
* @param context The plugin context. | ||
*/ | ||
export function buildJobParameters(params: { [name: string]: string }, context: PluginContext): JobParameter[] { | ||
const parameters: JobParameter[] = []; | ||
for (const [name, value] of Object.entries(params)) { | ||
parameters.push({ name, value: buildParameter(value, context) }); | ||
} | ||
return parameters; | ||
} | ||
|
||
/** | ||
* Builds the parameter value template as handlebars template. | ||
* @param value The parameter value template. | ||
* @param context The plugin context. | ||
*/ | ||
function buildParameter(value: string, context: PluginContext): string { | ||
return Handlebars.compile(value)(context); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { PluginConfig } from "../types/plugin-config"; | ||
|
||
export function getConfig(config: Partial<PluginConfig> = {}): Partial<PluginConfig> { | ||
return config; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { PluginContext } from "../types/plugin-context"; | ||
|
||
export function getContext(env: { [key: string]: string } = {}, branchName = "main"): PluginContext { | ||
return { | ||
env, | ||
commits: [], | ||
branch: { | ||
name: branchName | ||
}, | ||
logger: { | ||
await: jest.fn(), | ||
complete: jest.fn(), | ||
debug: jest.fn(), | ||
error: jest.fn(), | ||
fatal: jest.fn(), | ||
fav: jest.fn(), | ||
info: jest.fn(), | ||
log: jest.fn(), | ||
note: jest.fn(), | ||
pause: jest.fn(), | ||
pending: jest.fn(), | ||
star: jest.fn(), | ||
start: jest.fn(), | ||
success: jest.fn(), | ||
wait: jest.fn(), | ||
warn: jest.fn(), | ||
watch: jest.fn() | ||
}, | ||
nextRelease: { | ||
type: "major", | ||
name: "test", | ||
channel: "test", | ||
gitHead: "012345", | ||
gitTag: "v1.0.0", | ||
version: "1.0.0", | ||
notes: "Hello World" | ||
} | ||
}; | ||
} |
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
Oops, something went wrong.