Skip to content

Commit 2a1a6a1

Browse files
committed
Adds 2 new labs and updates the readme
1 parent 9ffb4dd commit 2a1a6a1

4 files changed

Lines changed: 206 additions & 1 deletion

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: 05-1. Use GitHub APIs
2+
on:
3+
workflow_dispatch:
4+
push:
5+
6+
# Limit the permissions of the GITHUB_TOKEN
7+
permissions:
8+
contents: read
9+
issues: write
10+
11+
jobs:
12+
13+
rest-api-create-and-close-issue:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/github-script@v6
17+
id: create-issue
18+
with:
19+
github-token: ${{secrets.GITHUB_TOKEN}}
20+
script: |
21+
const result = await github.rest.issues.create({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
title: 'Issue auto-created from workflow run ${{github.run_id}}',
25+
body: '👋 Thank you! We appreciate your contribution to this project.',
26+
labels: ["training"]
27+
})
28+
console.log(result)
29+
return result.data
30+
31+
- name: Displays create issue result
32+
run: echo "${{toJSON(steps.create-issue.outputs.result)}}"
33+
34+
# Add here the close-issue step
35+
36+
37+
graphql-api-query-issues:
38+
needs: rest-api-create-and-close-issue
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/github-script@v6
42+
id: issues-result
43+
with:
44+
script: |
45+
const query = `query($owner:String!, $name:String!, $label:String!) {
46+
repository(owner:$owner, name:$name){
47+
issues(first:100, labels: [$label]) {
48+
nodes {
49+
number,
50+
title
51+
}
52+
}
53+
}
54+
}`;
55+
const variables = {
56+
owner: context.repo.owner,
57+
name: context.repo.repo,
58+
label: 'training'
59+
}
60+
const result = await github.graphql(query, variables)
61+
console.log(result.repository.issues.nodes)
62+
return result
63+
64+
- name: Displays training issues
65+
run: echo "${{toJSON(steps.issues-result.outputs.result)}}"
66+
67+
68+
# Add here the labels query step
69+
70+
71+

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
### Module 3: Managing a branch protection rule
1616
- [ ] _Hands-on Lab:_ > [Activity 3](/labs/lab03.md)
1717

18+
### Module 4: GitHub Templates
19+
- [ ] _Hands-on Lab:_ > [Activity 2](/labs/lab04.md)
20+
21+
### Module 5: GitHub API
22+
- [ ] _Hands-on Lab:_ > [Activity 5](/labs/lab05.md)
23+
1824
---
1925

2026
## Additional Resources
@@ -31,6 +37,10 @@
3137
- [Repositories](https://docs.github.com/en/enterprise-cloud@latest/repositories)
3238
- [Roles in an organization](https://docs.github.com/en/organizations/managing-peoples-access-to-your-organization-with-roles/roles-in-an-organization#permission-levels-for-an-organization)
3339
- [Configuring SCIM provisioning for Enterprise Managed Users](https://docs.github.com/en/enterprise-cloud@latest/admin/identity-and-access-management/using-enterprise-managed-users-and-saml-for-iam/configuring-scim-provisioning-for-enterprise-managed-users)
40+
- [About Enterprise Managed Users](https://docs.github.com/en/enterprise-cloud@latest/admin/identity-and-access-management/using-enterprise-managed-users-for-iam/about-enterprise-managed-users)
41+
- [Managing a branch protection rule](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule)
42+
- [GitHub Blog Enterprise](https://github.blog/category/enterprise/)
43+
- [GitHub Actions - Security guides](https://docs.github.com/en/actions/security-guides)
3444

3545
### Admin Changelog
3646
- [GitHub Changelog](https://github.blog/changelog/)
@@ -41,9 +51,13 @@
4151
- [What's new for GitHub Enterprise - GitHub Universe 2021 - YouTube](https://www.youtube-nocookie.com/embed/ZZviWZgrqhM)
4252
- [GitHub in the Enterprise - GitHub Universe 2021 - YouTube](https://www.youtube.com/watch?v=1-i39RqaxRs)
4353
- [Enforcing information security policy through GitHub Enterprise - GitHub Universe 2021 - YouTube](https://www.youtube-nocookie.com/embed/DCu-ZTT7WTI)
54+
- [GitHub Universe](https://githubuniverse.com/)
4455

4556
### Articles & Guides
57+
- [Everything new from GitHub Universe 2022](https://github.blog/2022-11-09-everything-new-from-github-universe-2022/)
4658
- [Improved management for GitHub Enterprise owners | The GitHub Blog](https://github.blog/2022-03-10-improved-management-github-enterprise-owners/)
4759
- [How to secure your GitHub organization and enterprise account | The GitHub Blog](https://github.blog/2020-07-23-how-to-secure-your-github-organization-and-enterprise-account/)
4860
- [Connect GitHub Enterprise Cloud to Defender for Cloud Apps | Microsoft Docs](https://docs.microsoft.com/en-us/defender-cloud-apps/connect-github-ec)
49-
- [How Defender for Cloud Apps helps protect your GitHub Enterprise environment | Microsoft Docs](https://docs.microsoft.com/en-us/defender-cloud-apps/protect-github)
61+
- [How Defender for Cloud Apps helps protect your GitHub Enterprise environment | Microsoft Docs](https://docs.microsoft.com/en-us/defender-cloud-apps/protect-github)
62+
- [GitHub Workflow Guide](https://github.github.com/services-workflow-guide/#/)
63+
- [Removing sensitive data from a repository - GitHub Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository)

labs/lab04.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 4 - GitHub Templates
2+
In this lab you will create issue and pull request templates and make an existing repository a template.
3+
> Duration: 5-10 minutes
4+
5+
References:
6+
- [Issue & pull request templates](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests)
7+
- [Configuring issue templates for your repository](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository)
8+
- [Creating a pull request template for your repository](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository)
9+
- [Creating a template repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-template-repository)
10+
- [Creating a repository from a template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
11+
12+
## 2.1 Create issue templates
13+
14+
1. Navigate to the `Settings > General` page of your repository
15+
2. In the `Features > Issues` section, click `Set up templates` button
16+
3. Select a template from the list
17+
4. Review the template by clicking on `Preview and edit`
18+
5. Edit the issue if needed to add your changes
19+
6. Click on `Propose changes` to commit the tempaltes to your repository.
20+
7. Repeat steps 3) to 6) to add more issue templates
21+
22+
## 2.2 Create pull request templates
23+
24+
1. Navigate to the `main` branch of your repository
25+
2. Click `Add file` to create a new file
26+
3. Name the file `.github/pull_request_template.md`
27+
4. In the body of the file, add your template:
28+
5. `Propose new file` and commit it directly to the `main` branch
29+
```markdown
30+
Fixes #
31+
32+
### Changes proposed with this pull request:
33+
-
34+
-
35+
-
36+
37+
### Checklist
38+
- [ ] Check the commit's or even all commits' message styles matches our requested structure.
39+
- [ ] Check your code additions will fail neither code linting checks nor unit test.
40+
41+
```
42+
43+
## 2.3 Create a template repository
44+
45+
1. Navigate to the `Settings > General` page of your repository
46+
2. Select `Template repository` checkbox
47+
3. Navigate to your repository list and click `New repository`
48+
4. The `repository template` list should contain your new repository template
49+
5. _(Optional)_ Create a new repository from one of the templates
50+
6. _(Optional)_ Navigate to your repository template and click on the `Use this template` button
51+

labs/lab05.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# 5 - GitHub API - REST API & GraphQL API
2+
In this lab you will create a workflow that calls GitHub APIs using REST API and GraphQL API.
3+
> Duration: 15-20 minutes
4+
5+
References:
6+
- [GitHub GraphQL API - GitHub Docs](https://docs.github.com/en/graphql)
7+
- [GitHub REST API - GitHub Docs](https://docs.github.com/en/rest)
8+
- [Migrating from REST to GraphQL - GitHub Docs](https://docs.github.com/en/graphql/guides/migrating-from-rest-to-graphql)
9+
- [actions/github-script](https://github.com/actions/github-script)
10+
- [octokit/graphql-action](https://github.com/octokit/graphql-action)
11+
- [See octokit/rest.js for the API client documentation](https://octokit.github.io/rest.js/v18)
12+
13+
## 5.1 Develop a GitHub Action workflow that calls REST APIs
14+
15+
1. Open the workflow file [use-github-apis.yml](/.github/workflows/use-github-apis.yml)
16+
2. Edit the file and copy the following YAML content at the end of the `rest-api-create-and-close-issue` job:
17+
```YAML
18+
- uses: actions/github-script@v6
19+
id: close-issue
20+
with:
21+
github-token: ${{secrets.GITHUB_TOKEN}}
22+
script: |
23+
const result = await github.rest.issues.update({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
issue_number: ${{fromJSON(steps.create-issue.outputs.result).number}},
27+
state: 'closed'
28+
})
29+
console.log(result)
30+
```
31+
3. Commit the changes into the `main` branch
32+
4. Go to `Actions` and see the details of your running workflow
33+
34+
## 5.2 Develop a GitHub Action workflow that calls GraphQL APIs
35+
36+
1. Open the workflow file [use-github-apis.yml](/.github/workflows/use-github-apis.yml)
37+
2. Edit the file and copy the following YAML content at the end of the file:
38+
```YAML
39+
graphql-api-query-labels:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/github-script@v6
43+
id: labels-result
44+
with:
45+
script: |
46+
const query = `query($owner:String!, $name:String!) {
47+
repository(owner:$owner, name:$name){
48+
labels (last:100) {
49+
nodes {
50+
name,
51+
color,
52+
issues(last:100) {
53+
nodes {
54+
number
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}`;
61+
const variables = {
62+
owner: context.repo.owner,
63+
name: context.repo.repo
64+
}
65+
const result = await github.graphql(query, variables)
66+
console.log(result.repository.labels.nodes)
67+
```
68+
3. Commit the changes into the `main` branch
69+
4. Go to `Actions` and see the details of your running workflow

0 commit comments

Comments
 (0)