-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented inputs * added test cases * refactor action input * readme update * fix typo
- Loading branch information
1 parent
bc475e5
commit 1de9668
Showing
6 changed files
with
145 additions
and
0 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,27 @@ | ||
import { ArgumentMap } from "@aj/map/argument-map"; | ||
import { ActionEvent } from "@aj/action-event/action-event"; | ||
|
||
export class ActionInput { | ||
private input: ArgumentMap; | ||
private event: ActionEvent; | ||
|
||
constructor(event: ActionEvent) { | ||
this.input = new ArgumentMap("--input"); | ||
this.event = event; | ||
} | ||
|
||
get map() { | ||
return this.input.map; | ||
} | ||
|
||
toActArguments() { | ||
if (Object.keys(this.event.event).length > 0) { | ||
const eventCopy = { ...this.event.event }; | ||
eventCopy.inputs = Object.fromEntries(this.input.map); | ||
this.event.event = eventCopy; | ||
return []; | ||
} else { | ||
return this.input.toActArguments(); | ||
} | ||
} | ||
} |
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,43 @@ | ||
import { ActionEvent } from "@aj/action-event/action-event"; | ||
import { ActionInput } from "@aj/action-input/action-input"; | ||
|
||
describe("toActArguments", () => { | ||
test("event payload is defined", () => { | ||
const event = new ActionEvent(); | ||
const input = new ActionInput(event); | ||
|
||
event.event = { | ||
pull_request: { | ||
head: { | ||
ref: "branch", | ||
}, | ||
}, | ||
}; | ||
|
||
input.map.set("INPUT1", "value1"); | ||
expect(input.toActArguments()).toStrictEqual([]); | ||
expect(event.event).toStrictEqual({ | ||
pull_request: { | ||
head: { | ||
ref: "branch", | ||
}, | ||
}, | ||
inputs: { | ||
INPUT1: "value1", | ||
}, | ||
}); | ||
}); | ||
|
||
test("event payload is not defined", () => { | ||
const event = new ActionEvent(); | ||
const input = new ActionInput(event); | ||
input.map.set("INPUT1", "value1"); | ||
input.map.set("INPUT2", "value2"); | ||
expect(input.toActArguments()).toStrictEqual([ | ||
"--input", | ||
"INPUT1=value1", | ||
"--input", | ||
"INPUT2=value2", | ||
]); | ||
}); | ||
}); |
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,16 @@ | ||
name: Input | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
some_input: | ||
default: 'world' | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
input: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: input | ||
run: echo "${{ inputs.some_input }}" |