Skip to content

Commit 236ae36

Browse files
authored
Add the variables parameter in YAML format (#209)
1 parent 33084fb commit 236ae36

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,54 @@ jobs:
114114
previews:
115115
- merge-info
116116
- run: "echo merge state status: '${{ steps.test_with_mediaType_previews_yaml.outputs.data }}'"
117+
- uses: ./
118+
id: get_latest_release_with_variables_parameter
119+
env:
120+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121+
with:
122+
query: |
123+
query release($owner:String!,$repo:String!) {
124+
repository(owner:$owner,name:$repo) {
125+
releases(first:1) {
126+
nodes {
127+
name
128+
createdAt
129+
tagName
130+
description
131+
}
132+
}
133+
}
134+
}
135+
variables: |
136+
owner: ${{ github.event.repository.owner.name }}
137+
repo: ${{ github.event.repository.name }}
138+
- run: "echo latest release: '${{ steps.get_latest_release_with_variables_parameter.outputs.data }}'"
139+
- id: get_commits_of_pull_request_with_variables_parameter
140+
uses: ./
141+
env:
142+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
143+
with:
144+
query: |
145+
query pr_commits($pr_number: Int!) {
146+
repository(owner: "octokit", name: "graphql-action") {
147+
pullRequest(number: $pr_number) {
148+
commits(first: 10) {
149+
edges {
150+
node {
151+
commit {
152+
message
153+
}
154+
}
155+
}
156+
}
157+
}
158+
}
159+
}
160+
variables: |
161+
pr_number: 1
162+
- env:
163+
JSON_DATA: ${{ steps.get_commits_with_variables_parameter.outputs.data }}
164+
run: >
165+
COMMITS_COUNT=$(echo ${JSON_DATA} | jq
166+
'.repository.pullRequest.commits[] | length')
167+
[[ ${COMMITS_COUNT} -eq 6 ]] && exit 0 || exit 1

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,31 @@ jobs:
4242
- run: "echo 'latest release: ${{ steps.get_latest_release.outputs.data }}'"
4343
```
4444
45+
You can also use the `variables` parameter to pass variables.
46+
47+
```yml
48+
- uses: octokit/[email protected]
49+
with:
50+
query: |
51+
query release($owner:String!,$repo:String!) {
52+
repository(owner:$owner,name:$repo) {
53+
releases(first:1) {
54+
nodes {
55+
name
56+
createdAt
57+
tagName
58+
description
59+
}
60+
}
61+
}
62+
}
63+
variables: |
64+
owner: ${{ github.event.repository.owner.name }}
65+
repo: ${{ github.event.repository.name }}
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
```
69+
4570
To access deep values of `outputs.data`, use [`fromJSON()`](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson).
4671

4772
## Debugging

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ inputs:
99
required: true
1010
mediaType:
1111
description: "Enable previews - see https://github.com/octokit/graphql-action/blob/main/README.md#preview-media-types"
12+
variables:
13+
description: "Variables described in YAML"
1214
outputs:
1315
data:
1416
description: 'The "data" key of the GraphQL response body'

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ function getAllInputs() {
4545
return result;
4646
}
4747

48+
if (inputName === `variables`) {
49+
const variables = yaml.load(value);
50+
return { ...result, ...variables };
51+
}
52+
4853
result[inputName] = yaml.load(value);
4954
result[inputName] =
5055
result[inputName] == parseInt(result[inputName], 10)

0 commit comments

Comments
 (0)