Skip to content

Commit ccae354

Browse files
author
Niel Drummond
authored
Merge pull request #2 from fussybeaver/ND-add-wiremock
Add wiremock and github action
2 parents 2a6b280 + c316a78 commit ccae354

File tree

88 files changed

+8252
-1873
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8252
-1873
lines changed

.github/workflows/default.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
on: [push, pull_request]
2+
3+
name: Default
4+
5+
jobs:
6+
check:
7+
name: Check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout sources
11+
uses: actions/checkout@v2
12+
13+
- name: Install stable toolchain
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
profile: minimal
17+
toolchain: stable
18+
override: true
19+
20+
- name: Run cargo check
21+
uses: actions-rs/cargo@v1
22+
with:
23+
command: check
24+
args: --all-features
25+
26+
test:
27+
name: Test Suite
28+
runs-on: ubuntu-latest
29+
30+
services:
31+
wiremock:
32+
image: rodolpheche/wiremock
33+
ports:
34+
- 8080:8080
35+
options: --name wiremock -v ${{ github.workspace }}/tests/stubs:/home/wiremock
36+
37+
steps:
38+
- name: Checkout sources
39+
uses: actions/checkout@v2
40+
with:
41+
path: 'checkout'
42+
43+
- name: Move files
44+
run: sudo apt-get update && sudo apt-get install -y rsync && sudo rsync -avu checkout/ ./ && sudo chown -R 1001 .
45+
46+
- name: Restart wiremock
47+
uses: docker://docker
48+
with:
49+
args: docker restart wiremock
50+
51+
- name: Install stable toolchain
52+
uses: actions-rs/toolchain@v1
53+
with:
54+
profile: minimal
55+
toolchain: stable
56+
override: true
57+
58+
- name: Run cargo test
59+
uses: actions-rs/cargo@v1
60+
with:
61+
command: test
62+
args: --features isahc,mercy,squirrel-girl,inertia,starfox,mock --target x86_64-unknown-linux-gnu

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ switcheroo = []
4141
wyandotte = []
4242
zzzax = []
4343

44+
# Activate mock base url
45+
mock = []
46+
4447
[dependencies]
4548
base64 = "0.13"
4649
chrono = { version = "0.4", features = ["serde"] }

README.md

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
22
[![docs](https://docs.rs/roctogen/badge.svg)](https://docs.rs/roctogen/)
3+
[![GitHub workflow](https://github.com/github/docs/actions/workflows/default.yml/badge.svg)](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml)
34

45
## Roctogen: a rust client library for the GitHub v3 API
56

@@ -21,6 +22,44 @@ roctogen = "0.1.0"
2122

2223
[API docs](https://docs.rs/roctogen/latest).
2324

25+
[Endpoints](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).
26+
27+
Supported endpoints:
28+
---
29+
30+
- [Meta](https://docs.rs/roctogen/latest/roctogen/endpoints/meta/struct.Meta.html)
31+
- [Issues](https://docs.rs/roctogen/latest/roctogen/endpoints/issues/struct.Issues.html)
32+
- [Licenses](https://docs.rs/roctogen/latest/roctogen/endpoints/licenses/struct.Licenses.html)
33+
- [Reactions](https://docs.rs/roctogen/latest/roctogen/endpoints/reactions/struct.Reactions.html)
34+
- [Activity](https://docs.rs/roctogen/latest/roctogen/endpoints/activity/struct.Activity.html)
35+
- [Projects](https://docs.rs/roctogen/latest/roctogen/endpoints/projects/struct.Projects.html)
36+
- [Orgs](https://docs.rs/roctogen/latest/roctogen/endpoints/orgs/struct.Orgs.html)
37+
- [Users](https://docs.rs/roctogen/latest/roctogen/endpoints/users/struct.Users.html)
38+
- [Apps](https://docs.rs/roctogen/latest/roctogen/endpoints/apps/struct.Apps.html)
39+
- [AuditLog](https://docs.rs/roctogen/latest/roctogen/endpoints/audit_log/struct.AuditLog.html)
40+
- [RateLimit](https://docs.rs/roctogen/latest/roctogen/endpoints/rate_limit/struct.RateLimit.html)
41+
- [Repos](https://docs.rs/roctogen/latest/roctogen/endpoints/repos/struct.Repos.html)
42+
- [SecretScanning](https://docs.rs/roctogen/latest/roctogen/endpoints/secret_scanning/struct.SecretScanning.html)
43+
- [Packages](https://docs.rs/roctogen/latest/roctogen/endpoints/packages/struct.Packages.html)
44+
- [Search](https://docs.rs/roctogen/latest/roctogen/endpoints/search/struct.Search.html)
45+
- [Teams](https://docs.rs/roctogen/latest/roctogen/endpoints/teams/struct.Teams.html)
46+
- [Markdown](https://docs.rs/roctogen/latest/roctogen/endpoints/markdown/struct.Markdown.html)
47+
- [OauthAuthorizations](https://docs.rs/roctogen/latest/roctogen/endpoints/oauth_authorizations/struct.OauthAuthorizations.html)
48+
- [Actions](https://docs.rs/roctogen/latest/roctogen/endpoints/actions/struct.Actions.html)
49+
- [Migrations](https://docs.rs/roctogen/latest/roctogen/endpoints/migrations/struct.Migrations.html)
50+
- [Gists](https://docs.rs/roctogen/latest/roctogen/endpoints/gists/struct.Gists.html)
51+
- [CodesOfConduct](https://docs.rs/roctogen/latest/roctogen/endpoints/codes_of_conduct/struct.CodesOfConduct.html)
52+
- [Pulls](https://docs.rs/roctogen/latest/roctogen/endpoints/pulls/struct.Pulls.html)
53+
- [Gitignore](https://docs.rs/roctogen/latest/roctogen/endpoints/gitignore/struct.Gitignore.html)
54+
- [EnterpriseAdmin](https://docs.rs/roctogen/latest/roctogen/endpoints/enterprise_admin/struct.EnterpriseAdmin.html)
55+
- [Git](https://docs.rs/roctogen/latest/roctogen/endpoints/git/struct.Git.html)
56+
- [Scim](https://docs.rs/roctogen/latest/roctogen/endpoints/scim/struct.Scim.html)
57+
- [CodeScanning](https://docs.rs/roctogen/latest/roctogen/endpoints/code_scanning/struct.CodeScanning.html)
58+
- [Checks](https://docs.rs/roctogen/latest/roctogen/endpoints/checks/struct.Checks.html)
59+
- [Billing](https://docs.rs/roctogen/latest/roctogen/endpoints/billing/struct.Billing.html)
60+
- [Interactions](https://docs.rs/roctogen/latest/roctogen/endpoints/interactions/struct.Interactions.html)
61+
- [Emojis](https://docs.rs/roctogen/latest/roctogen/endpoints/emojis/struct.Emojis.html)
62+
2463
## Usage
2564

2665
A quick example of this library:
@@ -97,7 +136,7 @@ $ mvn -D org.slf4j.simpleLogger.defaultLogLevel=info clean compiler:compile gene
97136

98137
## Tests
99138

100-
Beware, tests are currently still doing real HTTP requests to the GitHub API.
139+
Beware, tests that are not run with the `mock` feature are currently still doing real HTTP requests to the GitHub API.
101140

102141
Run the wasm tests:
103142

@@ -111,4 +150,21 @@ Run the sync tests:
111150
$ cargo test --features isahc,mercy,squirrel-girl,inertia,starfox --target x86_64-unknown-linux-gnu -- --nocapture
112151
```
113152

153+
In order to avoid GitHub's API rate limiting, you can run the non-wasm tests using wiremock.
154+
You'll need to start wiremock in the background:
155+
156+
```nocompile
157+
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock
158+
rodolpheche/wiremock
159+
```
160+
161+
#### Regenerate the wiremock stubs
162+
163+
You should regenerate the stubs if the remote API has changed:
164+
165+
```nocompile
166+
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock -u (id -u):(id -g) rodolpheche/wiremock --verbose --proxy-all="https://api.github.com" --record-mappings
167+
```
168+
169+
114170
License: Apache-2.0

java/github/CodegenTag.java

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
public class CodegenTag extends CodegenObject {
1111
public String baseName;
12+
public String classname;
1213
public List<CodegenOperation> operations;
1314
public List<CodegenContent> contents = new ArrayList<>();
1415
public String getBaseName() {
@@ -28,6 +29,8 @@ public int hashCode() {
2829
final int prime = 31;
2930
int result = 1;
3031
result = prime * result + ((baseName == null) ? 0 : baseName.hashCode());
32+
result = prime * result + ((classname == null) ? 0 : classname.hashCode());
33+
result = prime * result + ((contents == null) ? 0 : contents.hashCode());
3134
result = prime * result + ((operations == null) ? 0 : operations.hashCode());
3235
return result;
3336
}
@@ -45,6 +48,16 @@ public boolean equals(Object obj) {
4548
return false;
4649
} else if (!baseName.equals(other.baseName))
4750
return false;
51+
if (classname == null) {
52+
if (other.classname != null)
53+
return false;
54+
} else if (!classname.equals(other.classname))
55+
return false;
56+
if (contents == null) {
57+
if (other.contents != null)
58+
return false;
59+
} else if (!contents.equals(other.contents))
60+
return false;
4861
if (operations == null) {
4962
if (other.operations != null)
5063
return false;
@@ -58,4 +71,10 @@ public List<CodegenContent> getContents() {
5871
public void setContents(List<CodegenContent> contents) {
5972
this.contents = contents;
6073
}
74+
public String getClassname() {
75+
return classname;
76+
}
77+
public void setClassname(String classname) {
78+
this.classname = classname;
79+
}
6180
}

java/github/GitHubCodegen.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.swagger.codegen.v3.CodegenParameter;
2323
import io.swagger.codegen.v3.CodegenProperty;
2424
import io.swagger.codegen.v3.CodegenResponse;
25-
import io.swagger.codegen.v3.generators.handlebars.java.JavaHelper;
25+
import io.swagger.codegen.v3.SupportingFile;
2626
import io.swagger.v3.oas.models.OpenAPI;
2727
import io.swagger.v3.oas.models.Operation;
2828
import io.swagger.v3.oas.models.info.Info;
@@ -39,7 +39,7 @@ public GitHubCodegen() {
3939
super();
4040

4141
additionalProperties.put("tags", tagList.values());
42-
// supportingFiles.add(new SupportingFile("api_impl.rs", "src", "api_impl.rs"));
42+
supportingFiles.add(new SupportingFile("lib.mustache", "src", "lib.rs"));
4343
}
4444

4545
private static HashMap<String, Object> patchOperationBodyNames = new HashMap();
@@ -186,6 +186,7 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
186186
} else {
187187
codegenTag = new CodegenTag();
188188
codegenTag.baseName = underscore(tag);
189+
codegenTag.classname = tag;
189190
codegenTag.operations = new ArrayList<CodegenOperation>();
190191
tagList.put(tag, codegenTag);
191192
}

java/github/RustServerCodegen.java

-5
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,8 @@ public RustServerCodegen() {
150150
* entire object tree available. If the input file has a suffix of `.mustache it
151151
* will be processed by the template engine. Otherwise, it will be copied
152152
*/
153-
//supportingFiles.clear();
154-
// supportingFiles.add(new SupportingFile("lib.mustache", "src", "lib.rs"));
155153
supportingFiles.add(new SupportingFile("models.mustache", "src", "models.rs"));
156154
supportingFiles.add(new SupportingFile("endpoints.mustache", "src/endpoints", "mod.rs"));
157-
//supportingFiles.add(new SupportingFile("api.mustache", "src", "api.rs"));
158-
// supportingFiles.add(new SupportingFile("client.mustache", "src",
159-
// "client.rs"));
160155

161156
}
162157

src/adapters/isahc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) fn fetch(request: Request<Body>) -> Result<Response<Body>, AdapterErr
2525
}
2626

2727
pub(crate) async fn fetch_async(_request: Request<Body>) -> Result<Response<Body>, AdapterError> {
28-
unimplemented!()
28+
todo!()
2929
}
3030

3131
impl<T: std::io::Read> GitHubResponseExt for Response<T> {

0 commit comments

Comments
 (0)