update code for create repository from template

Signed-off-by: Yang Ting <bonnie.young@maxwit.com>
This commit is contained in:
Yang Ting
2020-08-12 22:08:31 +08:00
parent bb4d44138a
commit 11bc669e1d
13 changed files with 55 additions and 83 deletions

View File

@@ -13,7 +13,7 @@ import static org.kohsuke.github.Previews.BAPTISE;
public class GHCreateRepositoryBuilder {
private final GitHub root;
protected final Requester builder;
private final String apiUrlTail;
private String apiUrlTail;
GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name) {
this.root = root;
@@ -22,22 +22,6 @@ public class GHCreateRepositoryBuilder {
this.builder.with("name", name);
}
GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name, Boolean isTemplate) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = root.createRequest();
this.builder.with("name", name);
this.builder.with("is_template", isTemplate);
}
GHCreateRepositoryBuilder(GitHub root, String apiUrlTail, String name, String owner) {
this.root = root;
this.apiUrlTail = apiUrlTail;
this.builder = root.createRequest();
this.builder.with("name", name);
this.builder.with("owner", owner);
}
/**
* Description for repository
*
@@ -218,6 +202,51 @@ public class GHCreateRepositoryBuilder {
return this;
}
/**
* Specifies whether the repository is a template.
*
* @param enabled
* true if enabled
* @return a builder to continue with building
*/
@Preview
@Deprecated
public GHCreateRepositoryBuilder templateRepository(boolean enabled) {
this.builder.withPreview(BAPTISE);
this.builder.with("is_template", enabled);
return this;
}
/**
* Specifies the ownership of the repository.
*
* @param owner
* organization or personage
* @return a builder to continue with building
*/
public GHCreateRepositoryBuilder owner(String owner) {
this.builder.with("owner", owner);
return this;
}
/**
* Create repository from template repository.
*
* @param templateOwner
* template repository owner
* @param templateRepo
* template repository
* @return a builder to continue with building
* @see <a href="https://developer.github.com/v3/previews/">GitHub API Previews</a>
*/
@Preview
@Deprecated
public GHCreateRepositoryBuilder fromTemplateRepository(String templateOwner, String templateRepo) {
this.builder.withPreview(BAPTISE);
this.apiUrlTail = "/repos/" + templateOwner + "/" + templateRepo + "/generate";
return this;
}
/**
* Creates a repository with all the parameters.
*
@@ -229,15 +258,4 @@ public class GHCreateRepositoryBuilder {
return builder.method("POST").withUrlPath(apiUrlTail).fetch(GHRepository.class).wrap(root);
}
/**
* Creates a repository with all the parameters, and with Preview BAPTISE for template repo.
*
* @return the gh repository
* @throws IOException
* if repsitory cannot be created
*/
public GHRepository createWithTemplate() throws IOException {
return builder.method("POST").withPreview(BAPTISE).withUrlPath(apiUrlTail).fetch(GHRepository.class).wrap(root);
}
}