Skip to content

Commit 3ec3f79

Browse files
committed
Add GitHub API example
1 parent 83e1135 commit 3ec3f79

File tree

5 files changed

+5987
-0
lines changed

5 files changed

+5987
-0
lines changed

github-api/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# GitHub REST API
2+
3+
You can use the [GitHub REST API](https://docs.github.com/en/rest) to create calls to get the data you need to integrate with [GitHub](http://github.com/).
4+
5+
## Run
6+
7+
Requirements:
8+
- [ScanAPI](https://pypi.org/project/scanapi/)
9+
- [GitHub Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
10+
11+
```shell
12+
$ git clone [email protected]:scanapi/examples.git
13+
$ cd github-api
14+
$ export GITHUB_API_TOKEN=<your_github_personal_access_token>
15+
$ scanapi run scanapi.yaml
16+
```
17+
18+
The report will be available at `scanapi-report.html`

github-api/gists.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
- name: gists
2+
path: gists
3+
headers:
4+
Authorization: token ${GITHUB_API_TOKEN}
5+
Accept: application/vnd.github.v3+json
6+
requests:
7+
- name: list all public gists
8+
tests:
9+
- name: status_code_is_200
10+
assert: ${{ response.status_code == 200 }}
11+
- name: create a gist
12+
method: post
13+
body:
14+
files:
15+
my_gist:
16+
content: "Hello, that is my gist. I'm a super gist! "
17+
description: hello!!
18+
public: true
19+
vars:
20+
gist_id: ${{ response.json()["id"] }}
21+
tests:
22+
- name: status_code_is_201
23+
assert: ${{ response.status_code == 201 }}
24+
endpoints:
25+
- name: details
26+
path: ${gist_id}
27+
requests:
28+
- name: gist details
29+
tests:
30+
- name: status_code_is_200
31+
assert: ${{ response.status_code == 200 }}
32+
- name: id matches
33+
assert: ${{ response.json()["id"] == "${gist_id}" }}
34+
- name: update gist
35+
method: patch
36+
body:
37+
files:
38+
my_gist:
39+
content: "Hello, that is my gist. I'm a super gist! "
40+
description: Hello super updated! Yay!
41+
public: true
42+
tests:
43+
- name: status_code_is_200
44+
assert: ${{ response.status_code == 200 }}
45+
- name: delete gist
46+
method: delete
47+
tests:
48+
- name: status_code_is_204
49+
assert: ${{ response.status_code == 204 }}

0 commit comments

Comments
 (0)