In this lab you will create a workflow that calls GitHub APIs using REST API and GraphQL API.
Duration: 15-20 minutes
References:
- GitHub GraphQL API - GitHub Docs
- GitHub REST API - GitHub Docs
- Migrating from REST to GraphQL - GitHub Docs
- actions/github-script
- octokit/graphql-action
- See octokit/rest.js for the API client documentation
- Open the workflow file use-github-apis.yml
- Edit the file and copy the following YAML content at the end of the
rest-api-create-and-close-issue
job:
- uses: actions/github-script@v6
id: close-issue
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const result = await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{fromJSON(steps.create-issue.outputs.result).number}},
state: 'closed'
})
console.log(result)
- Commit the changes into the
main
branch - Go to
Actions
and see the details of your running workflow
- Open the workflow file use-github-apis.yml
- Edit the file and copy the following YAML content at the end of the file:
graphql-api-query-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
id: labels-result
with:
script: |
const query = `query($owner:String!, $name:String!) {
repository(owner:$owner, name:$name){
labels (last:100) {
nodes {
name,
color,
issues(last:100) {
nodes {
number
}
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo
}
const result = await github.graphql(query, variables)
console.log(result.repository.labels.nodes)
- Commit the changes into the
main
branch - Go to
Actions
and see the details of your running workflow