Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- bulk update of repository options #939

Merged
merged 11 commits into from
Dec 29, 2020
32 changes: 24 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,37 @@ Example for a single test case:

`WireMockStatusReporterTest: GitHub proxying and user auth correctly configured for user login: <your login>`

Whenever you run tests with `-Dtest.github.useProxy`, they will try to get data from local files but will fallback to proxying to github if not found.

Whenever you run tests with `-Dtest.github.useProxy`, they will try to get data from local files but will fallback to proxying to GitHub if not found.

### Writing a new test

Once you have credentials setup, you add new test classes and test methods as you would normally.
Keep `useProxy` enabled and iterate on your tests as needed. Remember, while proxying your tests are interacting with GitHub - you will need to clean up your state between runs.

When you are ready to create a snapshot of your test data,
run your test with `test.github.takeSnapshot` ("-Dtest.github.takeSnapshot" as a Java VM option). For example:
#### Running tests using GitHub test proxy

Keep `useProxy` enabled and iterate on your tests as needed. With `useProxy` enabled your tests will interact with
GitHub - you will need to clean up your server-state between runs. This can be done manually to start with.
Once your test code is somewhat stable, use `getGitHubBeforeAfter()` to get a `GitHub` instance for test setup and cleanup.
Interactions with that `GitHub` instance will not be recorded as part of the test, keeping the test data files to a minimum.

#### Running tests against your personal GitHub user account

By default, test helper methods such as `getTempRepository()` target the `hub4j-test-org` GitHub organization.
Please request access to this org to record your tests before submitting a PR. This helps keep the project stable and nimble.
Until you have access (or if you don't want access), you can set the following additional system property to target
your personal github account.

`mvn install -Dtest.github.org=false -Dtest=YourTestClassName`

#### Taking a snapshot

When you are ready to create a snapshot of your test data, run your test with `test.github.takeSnapshot` ("-Dtest.github.takeSnapshot" as
a Java VM option). For example:

`mvn install -Dtest.github.takeSnapshot -Dtest=YourTestClassName`
`mvn install -Dtest.github.takeSnapshot -Dtest.github.org=false -Dtest=YourTestClassName`

The above command would create snapshot WireMock data files under the path `src/test/resources/org/kohsuhke/github/YourTestClassName/wiremock`.
Each method would get a separate director that would hold the data files for that test method.
The above command will create snapshot WireMock data files under the path `src/test/resources/org/kohsuhke/github/YourTestClassName/wiremock`.
Each method will get a separate directory that will hold the data files for that test method.

Add all files including the generated data to your commit and submit a PR.

Expand Down
218 changes: 46 additions & 172 deletions src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kohsuke.github;

import java.io.IOException;
import java.net.URL;

import static org.kohsuke.github.Previews.BAPTISTE;

Expand All @@ -10,110 +9,43 @@
*
* @author Kohsuke Kawaguchi
*/
public class GHCreateRepositoryBuilder extends GitHubInteractiveObject {
protected final Requester builder;
private String apiUrlTail;
public class GHCreateRepositoryBuilder extends GHRepositoryBuilder<GHCreateRepositoryBuilder> {

GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = root.createRequest();
this.builder.with("name", name);
}

/**
* Description for repository
*
* @param description
* description of repository
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder description(String description) {
this.builder.with("description", description);
return this;
}

/**
* Homepage for repository
*
* @param homepage
* homepage of repository
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder homepage(URL homepage) {
return homepage(homepage.toExternalForm());
}

/**
* Homepage for repository
*
* @param homepage
* homepage of repository
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder homepage(String homepage) {
this.builder.with("homepage", homepage);
return this;
}

/**
* Creates a private repository
*
* @param enabled
* private if true
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder private_(boolean enabled) {
this.builder.with("private", enabled);
return this;
}

/**
* Enables issue tracker
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder issues(boolean enabled) {
this.builder.with("has_issues", enabled);
return this;
}
public GHCreateRepositoryBuilder(String name, GitHub root, String apiTail) {
super(GHCreateRepositoryBuilder.class, root, null);
requester.method("POST").withUrlPath(apiTail);

/**
* Enables projects
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder projects(boolean enabled) {
this.builder.with("has_projects", enabled);
return this;
try {
name(name);
} catch (IOException e) {
// not going to happen here
}
}

/**
* Enables wiki
* Creates a default .gitignore
*
* @param enabled
* true if enabled
* @return a builder to continue with building
* @param language
* template to base the ignore file on
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
* @throws IOException
* In case of any networking error or error from the server.
*/
public GHCreateRepositoryBuilder wiki(boolean enabled) {
this.builder.with("has_wiki", enabled);
return this;
public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOException {
return with("gitignore_template", language);
}

/**
* Enables downloads
* Desired license template to apply
*
* @param enabled
* true if enabled
* @return a builder to continue with building
* @param license
* template to base the license file on
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
* @throws IOException
* In case of any networking error or error from the server.
*/
public GHCreateRepositoryBuilder downloads(boolean enabled) {
this.builder.with("has_downloads", enabled);
return this;
public GHCreateRepositoryBuilder licenseTemplate(String license) throws IOException {
return with("license_template", license);
}

/**
Expand All @@ -122,70 +54,11 @@ public GHCreateRepositoryBuilder downloads(boolean enabled) {
* @param enabled
* true if enabled
* @return a builder to continue with building
* @throws IOException
* In case of any networking error or error from the server.
*/
public GHCreateRepositoryBuilder autoInit(boolean enabled) {
this.builder.with("auto_init", enabled);
return this;
}

/**
* Allow or disallow squash-merging pull requests.
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder allowSquashMerge(boolean enabled) {
this.builder.with("allow_squash_merge", enabled);
return this;
}

/**
* Allow or disallow merging pull requests with a merge commit.
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder allowMergeCommit(boolean enabled) {
this.builder.with("allow_merge_commit", enabled);
return this;
}

/**
* Allow or disallow rebase-merging pull requests.
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder allowRebaseMerge(boolean enabled) {
this.builder.with("allow_rebase_merge", enabled);
return this;
}

/**
* Creates a default .gitignore
*
* @param language
* template to base the ignore file on
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
*/
public GHCreateRepositoryBuilder gitignoreTemplate(String language) {
this.builder.with("gitignore_template", language);
return this;
}

/**
* Desired license template to apply
*
* @param license
* template to base the license file on
* @return a builder to continue with building See https://developer.github.com/v3/repos/#create
*/
public GHCreateRepositoryBuilder licenseTemplate(String license) {
this.builder.with("license_template", license);
return this;
public GHCreateRepositoryBuilder autoInit(boolean enabled) throws IOException {
return with("auto_init", enabled);
}

/**
Expand All @@ -194,10 +67,12 @@ public GHCreateRepositoryBuilder licenseTemplate(String license) {
* @param team
* team to grant access to
* @return a builder to continue with building
* @throws IOException
* In case of any networking error or error from the server.
*/
public GHCreateRepositoryBuilder team(GHTeam team) {
public GHCreateRepositoryBuilder team(GHTeam team) throws IOException {
if (team != null)
this.builder.with("team_id", team.getId());
return with("team_id", team.getId());
return this;
}

Expand All @@ -207,13 +82,13 @@ public GHCreateRepositoryBuilder team(GHTeam team) {
* @param enabled
* true if enabled
* @return a builder to continue with building
* @throws IOException
* In case of any networking error or error from the server.
* @deprecated Use {@link #isTemplate(boolean)} method instead
*/
@Preview(BAPTISTE)
@Deprecated
public GHCreateRepositoryBuilder templateRepository(boolean enabled) {
this.builder.withPreview(BAPTISTE);
this.builder.with("is_template", enabled);
return this;
public GHCreateRepositoryBuilder templateRepository(boolean enabled) throws IOException {
return isTemplate(enabled);
}

/**
Expand All @@ -222,14 +97,15 @@ public GHCreateRepositoryBuilder templateRepository(boolean enabled) {
* @param owner
* organization or personage
* @return a builder to continue with building
* @throws IOException
* In case of any networking error or error from the server.
*/
public GHCreateRepositoryBuilder owner(String owner) {
this.builder.with("owner", owner);
return this;
public GHCreateRepositoryBuilder owner(String owner) throws IOException {
return with("owner", owner);
}

/**
* Create repository from template repository.
* Create repository from template repository
*
* @param templateOwner
* template repository owner
Expand All @@ -241,8 +117,7 @@ public GHCreateRepositoryBuilder owner(String owner) {
@Preview(BAPTISTE)
@Deprecated
public GHCreateRepositoryBuilder fromTemplateRepository(String templateOwner, String templateRepo) {
this.builder.withPreview(BAPTISTE);
this.apiUrlTail = "/repos/" + templateOwner + "/" + templateRepo + "/generate";
requester.withPreview(BAPTISTE).withUrlPath("/repos/" + templateOwner + "/" + templateRepo + "/generate");
return this;
}

Expand All @@ -251,10 +126,9 @@ public GHCreateRepositoryBuilder fromTemplateRepository(String templateOwner, St
*
* @return the gh repository
* @throws IOException
* if repsitory cannot be created
* if repository cannot be created
*/
public GHRepository create() throws IOException {
return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHRepository.class).wrap(root);
return done();
}

}
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public GHRepository createRepository(String name,
* @return the gh create repository builder
*/
public GHCreateRepositoryBuilder createRepository(String name) {
return new GHCreateRepositoryBuilder(root, "/orgs/" + login + "/repos", name);
return new GHCreateRepositoryBuilder(name, root, "/orgs/" + login + "/repos");
}

/**
Expand Down
Loading