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

Commit 7e3b107

Browse files
committed
more responses and logic
1 parent 6c25b2f commit 7e3b107

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

config.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,60 @@ steps:
172172
- type: removeBranchProtection
173173
- type: respond
174174
with: 08_experiment.md
175+
176+
- title: Integrating Actions with external APIs
177+
description: Write a new Action that call an external API
178+
event: pull_request.closed
179+
actions:
180+
- type: updateBranchProtection
181+
- type: createIssue
182+
body: 09_joking-around.md
183+
title: Knock Knock...
184+
action_id: jokeIssue
185+
data:
186+
actionsUrl: "%payload.repository.html_url%/actions"
187+
- type: respond
188+
with: 08_next-steps.md
189+
issue: Hello Action
190+
data:
191+
issueUrl: "%actions.jokeIssue.data.html_url%"
192+
- type: respond
193+
with: 09_new-action.md
194+
issue: Knock Knock...
195+
data:
196+
workflowFile: "%payload.repository.html_url%/edit/master/.github/workflows/my-workflow.yml"
197+
198+
- title: Add a second Action
199+
description: Create a pull request to add another Action
200+
event: pull_request
201+
# link: "{{ repoUrl }}/issue1/1"
202+
actions:
203+
- type: gate
204+
gates:
205+
# if the payload action is 'opened' OR 'edited'
206+
- left: "%payload.action%"
207+
operator: ===
208+
right: opened
209+
- left: "%payload.action%"
210+
operator: ===
211+
right: edited
212+
# AND the pull request title equals 'Initial Workflow'
213+
- type: gate
214+
left: "%payload.pull_request.title%"
215+
operator: ===
216+
right: Second Action
217+
218+
# if those statments FAIL... do this
219+
else:
220+
- type: respond
221+
with: e-rename-pr.md
222+
data:
223+
title: Initial Workflow
224+
# if those gates === true Then do this stuff
225+
###############################################################################################################
226+
- type: closeIssue
227+
issue: Knock Knock...
228+
- type: respond
229+
with: 10_some-markdown.md
230+
data:
231+
actionsUrl: "%payload.repository.html_url%/actions"

responses/08_next-steps.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Congrats on your first Action 🎉
2+
3+
Congratulations {{user.login}} you have officially written your first GitHub JavaScript Action!!!
4+
5+
That's super exciting news, but this lesson has just start, so let's head over to the [new issue I've opened]({{issueUrl}}) to continue writing Actions.

responses/09_joking-around.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## Who's there?
2+
3+
GitHub Actions... thats who!
4+
5+
The next Action we write is going to reach out to an external API and fetch data for consumption. Although your Action is bound to a step, which is bound to a workflow within your repository it is NOT bound to an isolated network. This means that we can leverage APIs from our favorite cloud providers, favorite pizza shops, social media or whatever API our developers need.
6+
7+
### What is an API
8+
9+
If you ask this question to anyone in the industry you'll likely get the obvious answer of "Application Programming Interface", which although true, doesn't exactly explain what one **is** or **does**.
10+
11+
Let's do a thought experiment to help understand the concept of an API.
12+
13+
I think most people are familiar with a 🚗 either through personal experience or some form of media. I also think it's safe to say that most people understand the concepts behind driving a car. By examining how we drive a car we can understand how APIs work in a fun way.
14+
15+
**Car Components**
16+
When driving a car there are a few components of the car that the driver interacts with directly. This wont be an all inclusive list, and each car varies to some degree, but so does each API. We will use the following components for our example:
17+
18+
- Gas pedal
19+
- Brake pedal
20+
- Steering wheel
21+
- Gear shift
22+
23+
As the driver of the car when we push one of the pedals, move the gear shift position or turn the steering wheel the car responds. Most of us don't know **exactly** how it responds though. We actually don't even think about the system that is in place to amplify the force applied to the steering wheel when we make a turn. We probably don't know if our vehicle has a hydraulic, electro-hydraulic or fully electric power steering system. What we do know is that when we turn the steering wheel the car responds by turning.
24+
25+
The steering wheel has become an API between the driver and the inner workings of the power steering system and the systems that it communicates with. You see, steering the car eventually turns the wheels of the car and that takes place through further interconnected systems that are abstracted away from the driver.
26+
27+
The same is true with the gear shift. When we move our car into a different state using the gear shift a series of events take place throughout the car to reflect that change. This could be going from a stopped position to driving forward. It could be going from forward motion to reverse. It could even be cycling through gears in the case of a manual transmission. Ultimately, by moving the gear shift we tell the car what to do when we apply the gas pedal.
28+
29+
Very simply the gas pedal changes the speed of our car. We press it down to go faster or lift pressure off of it to stop going faster. What about if we want to fully stop? The gas pedal, gear shift and steering wheel wont exactly help us do that, hence the need for a brake pedal.
30+
31+
All of these systems, these APIs designed to help a human drive a car, are constantly communicating with one another to produce a moving vehicle. The driver didn't have to concern themselves with the implementation, platform, architecture, complex queries or manufacturer differences of each car. No, the driver just needed to concern themselves with how a steering wheel, gas pedal, brake pedal and gear shift work.
32+
33+
What gets even better is that the API for a car is pretty standard from one car to the next. Once you learn one steering wheel you pretty much know them all!
34+
35+
**Standard API Types:**
36+
37+
This concept is also prevalent in real world APIs. There are many **standard** types of APIs and if you understand each standard then you ultimately understand how to use that API to your advantage.
38+
39+
The most common types of API at the time this course was written are:
40+
41+
- REST
42+
- SOAP
43+
- XML-RPC
44+
- JSON-RPC
45+
46+
Going into detail about each standard is beyond the scope of this course, however it's important to understand that there are many standards out there. Although there are many standards the purpose of each API is to give your program or service the ability to communicate easily with another program or service without the need to know the implementation details.
47+
48+
APIs also give you, the developer, the ability to give others access to specific functionality or resources within your own program or service.
49+
50+
### What about our Action?
51+
52+
We are now going to write an Action that reaches out to a service through its API to get us a random joke. We will then display that joke on the [Actions tab]({{actionsUrl}}).
53+
54+
For our purposes the API we use will not require authentication, however that is a limitation of the course content and not the GitHub Actions platform. If you need to store secrets, like API keys, for your workflow to use you will need to configure [secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) as inputs.
55+
56+
We are also going to demonstrate having multiple files make up an Action as well as importing other external libraries for your Action to use.
57+
58+
What are we waiting for, let's get started 😉

responses/09_new-action.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### :keyboard: Activity: Setting up the next Action
2+
3+
Before we continue we are going to need to do a few things. First and foremost our workflow is currently setup to run each time there is a `push` event to this repository. Let's comment out our current workflow to prevent things from running but preserve the things you've worked on up to this point.
4+
5+
<!-- add action.yml -->
6+
<!-- open pull request -->

0 commit comments

Comments
 (0)