You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- content: "A programming language that compiles to JavaScript."
20
20
isCorrect: false
21
-
explanation: "GitHub Script is not a programming language."
22
-
- content: "An automation syntax for GitHub Shell."
21
+
explanation: "GitHub Script isn't a programming language."
22
+
- content: "An automation syntax for GitHub shell."
23
23
isCorrect: false
24
-
explanation: "GitHub Script is not a scripting language."
24
+
explanation: "GitHub Script isn't a scripting language."
25
25
- content: "A workflow action that enables GitHub API access from GitHub Actions."
26
26
isCorrect: true
27
27
explanation: "It allows you to script any API usage that is available through the octokit/rest.js library."
28
28
- content: "What is the difference between GitHub Script and GitHub Actions?"
29
29
choices:
30
30
- content: "GitHub Actions is for automating build and release pipelines. It was written in the GitHub Script programming language."
31
31
isCorrect: false
32
-
explanation: "GitHub Script is not a programming language."
32
+
explanation: "GitHub Script isn't a programming language."
33
33
- content: "GitHub Actions is a workflow engine that automates the execution of actions. GitHub Script is one of the actions available for use in a workflow."
34
34
isCorrect: true
35
-
explanation: "GitHub Actions workflows may contain GitHub Script actions."
35
+
explanation: "GitHub Actions workflows can contain GitHub Script actions."
36
36
- content: "GitHub Actions automates workflows that run inside GitHub. GitHub Script automates workflows that run outside of GitHub."
37
37
isCorrect: false
38
38
explanation: "GitHub Script is a workflow action that runs inside GitHub."
39
39
- content: "Why would someone use the following YAML in a GitHub Script action: `if: contains(github.event.issue.labels.*.name, 'bug')`?"
40
40
choices:
41
-
- content: "To ensure that the script only runs when the target issue has been labeled as a bug."
41
+
- content: "To ensure that the script runs only when the target issue is labeled as a bug."
42
42
isCorrect: true
43
-
explanation: "This expression instructs the action to ignore issues that are not labeled as a bug."
44
-
- content: "To make sure that new issue names do not violate the bug reporting policy when created."
43
+
explanation: "This expression instructs the action to ignore issues that aren't labeled as bugs."
44
+
- content: "To make sure that new issue names don't violate the bug reporting policy when issues are created."
45
45
isCorrect: false
46
-
explanation: "This snippet will not help you enforce issue creation policy."
Copy file name to clipboardExpand all lines: learn-pr/github/automate-github-using-github-script/includes/1-introduction.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
GitHub Script is a workflow action that provides you with access to the GitHub API from within your GitHub Actions. It offers convenient support for any API usage available in [octokit/rest.js](https://octokit.github.io/rest.js/?azure-portal=true).
1
+
GitHub Script is a workflow action that provides you with access to the GitHub API from within GitHub Actions. It offers convenient support for any API usage that's available in [octokit/rest.js](https://octokit.github.io/rest.js/?azure-portal=true).
2
2
3
-
Suppose you maintain a vibrant GitHub repository. Your project has a substantial number of consumers and contributors, and you want to make sure they have a welcoming experience. You also find that the responsibilities of managing the team's planning and workload can really add up. You need a solution that allows you to hand off some of the mundane tasks to automation so that you can focus on areas where you really add value. You know that GitHub offers an API that will let you automatically reply to new issues and begin the triage workflow for new bug reports. You just haven't invested the time in figuring it all out, until now.
3
+
Suppose you maintain a vibrant GitHub repository. Your project has a substantial number of consumers and contributors, and you want to make sure they have a welcoming experience. You also find that the responsibilities of managing the team's planning and workload can really add up. You need a solution that enables you to hand off some of the mundane tasks to automation so that you can focus on areas where you really add value. You know that GitHub provides an API that lets you automatically reply to new issues and begin the triage workflow for new bug reports. You just haven't invested the time in figuring it all out, until now.
4
4
5
5
In this module, you'll learn how to interact with the GitHub API from a GitHub Actions workflow by using GitHub Script.
6
6
@@ -9,8 +9,8 @@ In this module, you'll learn how to interact with the GitHub API from a GitHub A
9
9
In this module, you'll:
10
10
11
11
- Use GitHub Script in your workflow.
12
-
- Comment on issues using octokit.
13
-
- Add issues to a project board using octokit.
12
+
- Comment on issues by using Octokit.
13
+
- Add issues to a project board by using Octokit.
14
14
- Use the workflow expression syntax to filter when jobs run in a workflow.
Copy file name to clipboardExpand all lines: learn-pr/github/automate-github-using-github-script/includes/2-what-is-github-script.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,44 +1,44 @@
1
-
Here, we'll discuss how GitHub Script lets you automate common GitHub processes using GitHub Actions workflows.
1
+
In this unit, you'll learn how GitHub Script enables you to automate common GitHub processes by using GitHub Actions workflows.
2
2
3
3
## What is GitHub Script?
4
4
5
-
[GitHub Script](https://github.com/actions/github-script?azure-portal=true) is an action that provides an authenticated [octokit](https://octokit.github.io/rest.js/?azure-portal=true) client and allows JavaScript to be written directly in a workflow file. It runs in [Node.js](https://nodejs.org/?azure-portal=true), so you have the power of that platform available when writing scripts.
5
+
[GitHub Script](https://github.com/actions/github-script?azure-portal=true) is an action that provides an authenticated [Octokit](https://octokit.github.io/rest.js/?azure-portal=true) client and enables JavaScript to be written directly in a workflow file. It runs in [Node.js](https://nodejs.org/?azure-portal=true), so you have the power of that platform available when you write scripts.
6
6
7
-
## What is octokit?
7
+
## What is Octokit?
8
8
9
-
octokit is the official collection of clients for the GitHub API. One of these clients, rest.js, provides JavaScript access to GitHub's REST interface.
9
+
Octokit is the official collection of clients for the GitHub API. One of these clients, rest.js, provides JavaScript access to the GitHub REST interface.
10
10
11
11
You have always been able to automate the GitHub API via octokit/rest.js, although it could be a chore to properly set up and maintain. One of the great advantages to using GitHub Script is that it handles all of this overhead so you can immediately start using the API. You don't need to worry about dependencies, configuration, or even authentication.
12
12
13
13
### What can octokit/rest.js do?
14
14
15
-
The short answer is that it can do virtually anything with respect to automating GitHub. Not only do you have access to commits, pull requests, and issues, but you also have access to users, projects, and organizations. You can retrieve lists of commonly used files, like popular licenses or `.gitignore` files. You can even render Markdown.
15
+
The short answer is that it can do virtually anything with respect to automating GitHub. In addition to having access to commits, pull requests, and issues, you also have access to users, projects, and organizations. You can retrieve lists of commonly used files, like popular licenses or `.gitignore` files. You can even render Markdown.
16
16
17
-
If you're building something that integrates GitHub, the odds are good that you'll find what you're looking for in [the full octokit/rest.js documentation](https://octokit.github.io/rest.js/?azure-portal=true).
17
+
If you're creating something that integrates GitHub, the odds are good that you'll find what you're looking for in [the full octokit/rest.js documentation](https://octokit.github.io/rest.js/?azure-portal=true).
18
18
19
19
### How is using GitHub Script different from octokit/rest.js?
20
20
21
-
The main difference in usage is that GitHub Script provides you with a preauthenticated octokit/rest.js client named `github`.
21
+
The main difference in usage is that GitHub Script provides a preauthenticated octokit/rest.js client named `github`.
22
22
23
-
So instead of:
23
+
So instead of
24
24
25
25
`octokit.issues.createComment({`
26
26
27
-
You'd use:
27
+
you use
28
28
29
-
`github.issues.createComment({`
29
+
`github.issues.createComment({`.
30
30
31
31
In addition to the `github` variable, the following variables are also provided:
32
32
33
-
-`context` is an object containing the [context of the workflow run](https://github.com/actions/toolkit/blob/master/packages/github/src/context.ts?azure-portal=true).
33
+
-`context` is an object that contains the [context of the workflow run](https://github.com/actions/toolkit/blob/master/packages/github/src/context.ts?azure-portal=true).
34
34
-`core` is a reference to the [@actions/core](https://github.com/actions/toolkit/tree/master/packages/core?azure-portal=true) package.
35
35
-`io` is a reference to the [@actions/io](https://github.com/actions/toolkit/tree/master/packages/io?azure-portal=true) package.
36
36
37
-
## Building a workflow that uses GitHub Script
37
+
## Creating a workflow that uses GitHub Script
38
38
39
-
GitHub Script actions fit into a workflow like any other action. As a result, you can even mix them in with existing workflows, such as those you may already have set up for CI/CD. To illustrate its convenience, we'll now construct a complete workflow that uses GitHub Script to automatically post a comment to all newly created issues.
39
+
GitHub Script actions fit into a workflow like any other action. As a result, you can even mix them in with existing workflows, like those you might have already set up for CI/CD. To illustrate the convenience of GitHub Script, you'll now construct a complete workflow that uses it to automatically post a comment to all newly created issues.
40
40
41
-
We'll start off with a `name` and an `on` clause that specifies that this workflow runs when issues are opened.
41
+
You'll start off with a `name` and an `on` clause that specifies that the workflow runs when issues are opened:
42
42
43
43
```yaml
44
44
name: Learning GitHub Script
@@ -48,7 +48,7 @@ on:
48
48
types: [opened]
49
49
```
50
50
51
-
Next, we'll define a job named `comment` that runs on Linux with a series of steps.
51
+
Next, you'll define a job named `comment` that runs on Linux with a series of steps:
52
52
53
53
```yaml
54
54
jobs:
@@ -72,25 +72,25 @@ In this case, there's only one step: the GitHub Script action.
72
72
})
73
73
```
74
74
75
-
Using GitHub Actions can really help automate the events that take place in your repositories. Imagine that a repository visitor opened a new issue containing information about a critical bug. You might want to thank them for bringing that to your attention; however, this simple task can become overwhelming as your repository attracts more visitors. By automating an issue comment, you could automate the process of thanking visitors every single time.
75
+
Using GitHub Actions can really help automate the events that take place in your repositories. Imagine that a repository visitor opened a new issue containing information about a critical bug. You might want to thank them for bringing the bug to your attention, but this simple task can become overwhelming as your repository attracts more visitors. By automating an issue comment, you can automate the process of thanking visitors every time.
The `actions/[email protected]` action, also known as GitHub Script, does all the heavy lifting for our integration with the GitHub API.
79
+
The `actions/[email protected]` action, also known as GitHub Script, does all the difficult work for your integration with the GitHub API.
80
80
81
81
This action requires a `github-token` that's provided at runtime so that requests are authenticated. This is automatically done for you, so you can use that code as-is.
82
82
83
83
The `script` parameter can be virtually any JavaScript that uses the octokit/rest/js client stored in `github`. In this case, it's just one line (split across multiple lines for readability) that creates a hardcoded comment.
84
84
85
-
After the workflow is run, GitHub Script logs the code it executed for review on the **Actions** tab.
85
+
After the workflow runs, GitHub Script logs the code it ran for review on the **Actions** tab:
86
86
87
-

87
+

88
88
89
89
### Running from a separate file
90
90
91
-
Sometimes, you might need to use significant code to fulfill your GitHub Script scenario. When that happens, you can keep the script in a separate file and reference it from the workflow instead of putting all the script inline.
91
+
You might sometimes need to use a significant amount of code to meet your GitHub Script scenario. When that happens, you can keep the script in a separate file and reference it from the workflow instead of putting all the script inline.
92
92
93
-
Here's an example of a simple workflow that does this:
93
+
Here's an example of a simple workflow that uses that technique:
0 commit comments