Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 2ec65e0

Browse files
committed
adding more responses
1 parent b0bf0d0 commit 2ec65e0

15 files changed

+244
-141
lines changed

config.yml

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ template:
66
repo: write-github-script-template
77
name: write-github-script
88
before:
9+
- type: updateBranchProtection
910
- type: createIssue
1011
title: Start here!
11-
body: 01_welcome-issue.md
12+
body: 00_welcome-issue.md
1213
action_id: welcomeIssue
1314
- type: respond
15+
with: 00_explain-gh-script.md
1416
issue: "%actions.welcomeIssue.data.number%"
15-
with: 01_welcome-activity.md
17+
- type: respond
18+
with: 00_octokit-comparison.md
19+
issue: "%actions.welcomeIssue.data.number%"
20+
- type: respond
21+
issue: "%actions.welcomeIssue.data.number%"
22+
with: 00_welcome-activity.md
1623
data:
1724
quicklink: "%payload.repository.html_url%/new/master?filename=.github/workflows/my-workflow.yml&workflow_template=blank"
1825
actionsUrl: "%payload.repository.html_url%/actions/new"
@@ -21,7 +28,7 @@ steps:
2128
- title: Setup a workflow file
2229
description: Create a pull request to add a workflow
2330
event: pull_request
24-
link: "{{ repoUrl }}/issues/%payload.pull_request.number%"
31+
link: "{{ repoUrl }}/issues/1"
2532
actions:
2633
- type: gate
2734
gates:
@@ -82,52 +89,43 @@ steps:
8289
pullUrl: "%payload.pull_request.html_url%"
8390
- type: closeIssue
8491
issue: Start here!
92+
- type: removeBranchProtection
8593
- type: respond
86-
with: 01_explain-workflow.md
94+
with: 01_merg-workflow.md
8795
data:
8896
actionsUrl: "%payload.repository.html_url%/actions"
89-
- type: respond
90-
with: 02_modify-workflow.md
91-
data:
92-
workflowFile: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/my-workflow.yml"
9397

9498
- title: Open an issue to trigger GitHub Script workflow
9599
description: Use GitHub script to comment when an issue is opened
96-
event: pull_request.synchronize
97-
link: "{{ repoUrl }}/issues/%payload.pull_request.number%"
100+
event: pull_request.closed
101+
link: "{{ repoUrl }}/pull/2"
102+
actions:
103+
- type: updateBranchProtection
104+
- type: createIssue
105+
title: Create an issue comment
106+
body: 02_workflow-triggered.md
107+
action_id: triggerIssue
108+
- type: respond
109+
with: new-issue.md
110+
issue: Create my-workflow.yml
111+
data:
112+
issueURL: "%actions.triggerIssue.data.html_url%"
113+
114+
- title: The workflow has commented
115+
description: a response after the workflow has run
116+
event: check_suite.completed
117+
link: "{{repoUrl}}/issues/3"
98118
actions:
99-
#######################################################
100-
# Validate the filepath for the my-workflow.yml file
101-
# get tree
102-
- type: getTree
103-
action_id: isInTree
104-
recursive: true
105-
sha: "%payload.pull_request.head.sha%"
106-
# check for a file in a tree
107119
- type: gate
108-
left: "%actions.isInTree.data.tree%"
109-
operator: includes
110-
right: "path:.github/workflows/my-workflow.yml"
120+
left: "%payload.check_suite.app.name%"
121+
operator: ===
122+
right: "GitHub Actions"
111123
else:
112-
# if file isn't where expected find true location
113-
- type: findInTree
114-
path: my-workflow.yml
115-
tree: "%actions.isInTree.data.tree%"
116-
# multiple: true
117-
action_id: fileLocation
118-
# help user with proper file location
119124
- type: respond
120-
with: e-wrong-file-location.md
125+
issue: Create an issue comment
126+
with: debug.md
121127
data:
122-
haveFile: "%actions.fileLocation.path%"
123-
needFile: ".github/actions/cat-facts/action.yml"
124-
editLink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/%actions.fileLocation.path%"
125-
fileName: my-workflow.yml
126-
# End filepath verification
127-
#######################################################
128+
debug: "%payload%"
128129
- type: respond
129-
with: 03_create-an-issue.md
130-
data:
131-
pullUrl: "%payload.pull_request.html_url%"
132-
actionsUrl: "%payload.repository.html_url%/actions"
133-
workflowFile: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/my-workflow.yml"
130+
with: 03_workflow-success.md
131+
issue: Create an issue comment

responses/00_explain-gh-script.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## Create an issue comment
2+
3+
If we take a look at the [Octokit documentation](https://octokit.github.io/rest.js/v17#issues-create-comment) on how to create issue comments we we are greeted with the following method:
4+
5+
**someFile.js**
6+
7+
```javascript
8+
octokit.issues.createComment({
9+
owner,
10+
repo,
11+
issue_number,
12+
body
13+
});
14+
```
15+
16+
Okay, that doesn't seem so hard. Now that we know how to do it with Octokit let's take a look at how to use GitHub Script to create an issue comment:
17+
18+
**my-workflow.yml**
19+
20+
```yaml
21+
- uses: actions/github-script@0.8.0
22+
with:
23+
github-token: ${{secrets.GITHUB_TOKEN}}
24+
script: |
25+
github.issues.createComment({
26+
issue_number: context.issue.number,
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
body: '👋 Thanks for reporting!'
30+
})
31+
```
32+
33+
## Open a pull request
34+
35+
Now let's examine what it's like to open a pull request with octokit/rest.js:
36+
37+
**someFile.js**
38+
39+
```javascript
40+
octokit.pulls.create({
41+
owner,
42+
repo,
43+
title,
44+
head,
45+
base
46+
});
47+
```
48+
49+
Again, that's not too hard at all. Now let's do the same thing, only using the GitHub Script action:
50+
51+
```yml
52+
- uses: actions/github-script@0.8.0
53+
with:
54+
github-token: ${{secrets.GITHUB_TOKEN}}
55+
script: |
56+
github.pull.create({
57+
repo: github.context.repo.repo,
58+
owner: github.context.repo.owner,
59+
head: github.context.ref,
60+
base: "master",
61+
title: "from my action",
62+
body: "## I totally used GitHub Script to pull this off 🔥"
63+
})
64+
```

responses/00_octokit-comparison.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## That's not much different, so why might I want to use GitHub Script?
2+
3+
With GitHub Script you don't have to worry about
4+
5+
- Building a custom action to create this issue comment.
6+
- No Octokit dependencies to worry about.
7+
- No additional packages to manage.
8+
- No need to write action metadata.
9+
- No need to write source code to handle this Octokit method.
10+
11+
Using GitHub Script instead of writing custom actions for repository related tasks can prove to be a much more light-weight solution in most cases.
12+
13+
Anything you can do with Octokit can be accomplished with GitHub Script 🎉!
14+
15+
---
16+
17+
_You may have noticed that when using GitHub Script the method call starts with `github` and not `octokit`. This is because GitHub Script provides you with a pre-authenticated octokit/rest.js client stored in a variable named `github`._
18+
19+
_`context` is a reference to an object containing the [context of the current workflow run](https://github.com/actions/toolkit/blob/master/packages/github/src/context.ts)_

responses/00_welcome-activity.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Configuring a workflow
2+
3+
Actions are enabled on your repository by default, but we still have to tell our repository to use them. We do this by creating a workflow file in our repository.
4+
5+
If you've been following the learning path for GitHub Actions then this task is quite familiar to you.
6+
7+
<details><summary>Brand new to GitHub Actions? Click here to learn about workflows!</summary>
8+
9+
#### What is a workflow file?
10+
11+
A **workflow** file can be thought of as the recipe for automating a task. They house the start to finish instructions, in the form of `jobs` and `steps`, for what should happen based on specific triggers.
12+
13+
Your repository can contain multiple **workflow** files that carry out a wide variety of tasks. It is important to consider this when deciding on a name for your **workflow**. The name you choose should reflect the tasks being performed.
14+
15+
</details>
16+
17+
<br>
18+
19+
<!-- 💻 Actively learn about workflows by enrolling in [this Learning Lab course which has no name or content yet]() -->
20+
21+
📖 Read more about [workflows](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#choosing-the-type-of-actions-for-your-workflow)
22+
23+
### :keyboard: Activity: Respond to an issue when it get's opened
24+
25+
1. Create a new workflow file titled `.github/workflows/my-workflow.yml` with the following contents:
26+
You can use [this quicklink]({{quicklink}}) to easily create this file
27+
28+
```yaml
29+
name: Learning GitHub Script
30+
31+
on:
32+
issues:
33+
types: [opened]
34+
35+
jobs:
36+
comment:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/github-script@0.8.0
40+
with:
41+
github-token: {% raw %}${{secrets.GITHUB_TOKEN}}{% endraw %}
42+
script: |
43+
github.issues.createComment({
44+
issue_number: context.issue.number,
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
body: "🎉 You've created this issue comment using GitHub Script!!!"
48+
})
49+
```
50+
51+
1. Commit the workflow to a new branch.
52+
1. Create a pull request titled **Create my-workflow.yml**.
53+
1. Supply the pull request body content and click `Create pull request`.
54+
55+
_It is important to place meaningful content into the body of the pull requests you create throughout this course. This repository will stay with you long after you complete the course. It is advisable that you use the body of the pull requests you create as a way to take long lived notes about thing you want to remember._
56+
57+
<details><summary>Suggested body content</summary>
58+
59+
`Workflow files are the recipe for task automation. This is where actions are placed if I want to use them for a task.`
60+
61+
</details>
62+
63+
---
64+
65+
I'll respond in the new pull request when I detect it has been created.

responses/00_welcome-issue.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Hi there 👋!
2+
3+
Hello @{{user.login}}, I'm so excited to teach you how to use GitHub Script in your workflows 😄
4+
5+
## What is GitHub Script?
6+
7+
<p align="center">
8+
<img src="https://user-images.githubusercontent.com/38021615/76347761-5ce75d00-62c4-11ea-835b-35660b5188c8.png" alt="octokit logo" height=200/>
9+
</p>
10+
11+
[GitHub Script](https://github.com/actions/github-script) is a really awesome action that allows you to quickly interact with the GitHub API directly in your workflow!
12+
13+
This allows you to use the workflow context to script any API usage that is available through the octokit/rest.js library without the need to build a bulky custom action to do so.
14+
15+
📖 See [octokit/rest.js](https://octokit.github.io/rest.js/) for the API client documentation.
16+
17+
Let's take a closer look at how this action compares to Octokit.

responses/01_explain-workflow.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

responses/01_merge-workflow.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## You have triggered a workflow!
2+
3+
Great job @{{user.login}}, you successfully added a workflow to this repository 🎉!
4+
5+
Since this workflow has a trigger that pertains to the repository as a whole, rather than just this branch, we will need to merge this pull request before we can start using it.
6+
7+
Let's go ahead and do this now.
8+
9+
### :keyboard: Activity: Merge the workflow
10+
11+
When you are ready, merge this pull request.
12+
13+
---
14+
15+
Once you have merged this pull request I will open a new issue so we can see this workflow in action!
16+
17+
Oh, I'll also be responding to you from that issue!

responses/01_welcome-activity.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

responses/01_welcome-issue.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)