Merge branch 'master' into AffiliationFilter

This commit is contained in:
Rob Rodrigues
2020-11-25 13:10:09 -08:00
committed by GitHub
18 changed files with 307 additions and 14 deletions

View File

@@ -24,6 +24,9 @@ public class GHDeployment extends GHObject {
protected String statuses_url;
protected String repository_url;
protected GHUser creator;
protected String original_environment;
protected boolean transient_environment;
protected boolean production_environment;
GHDeployment wrap(GHRepository owner) {
this.owner = owner;
@@ -89,6 +92,19 @@ public class GHDeployment extends GHObject {
return payload;
}
/**
* The environment defined when the deployment was first created.
*
* @deprecated until preview feature has graduated to stable
*
* @return the original deployment environment
*/
@Deprecated
@Preview(Previews.FLASH)
public String getOriginalEnvironment() {
return original_environment;
}
/**
* Gets environment.
*
@@ -98,6 +114,33 @@ public class GHDeployment extends GHObject {
return environment;
}
/**
* Specifies if the given environment is specific to the deployment and will no longer exist at some point in the
* future.
*
* @deprecated until preview feature has graduated to stable
*
* @return the environment is transient
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public boolean isTransientEnvironment() {
return transient_environment;
}
/**
* Specifies if the given environment is one that end-users directly interact with.
*
* @deprecated until preview feature has graduated to stable
*
* @return the environment is used by end-users directly
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public boolean isProductionEnvironment() {
return production_environment;
}
/**
* Gets creator.
*
@@ -154,6 +197,8 @@ public class GHDeployment extends GHObject {
public PagedIterable<GHDeploymentStatus> listStatuses() {
return root.createRequest()
.withUrlPath(statuses_url)
.withPreview(Previews.ANT_MAN)
.withPreview(Previews.FLASH)
.toIterable(GHDeploymentStatus[].class, item -> item.wrap(owner));
}

View File

@@ -19,7 +19,10 @@ public class GHDeploymentBuilder {
*/
public GHDeploymentBuilder(GHRepository repo) {
this.repo = repo;
this.builder = repo.root.createRequest().method("POST");
this.builder = repo.root.createRequest()
.withPreview(Previews.ANT_MAN)
.withPreview(Previews.FLASH)
.method("POST");
}
/**
@@ -40,6 +43,7 @@ public class GHDeploymentBuilder {
*
* @param branch
* the branch
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder ref(String branch) {
@@ -52,6 +56,7 @@ public class GHDeploymentBuilder {
*
* @param task
* the task
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder task(String task) {
@@ -64,6 +69,7 @@ public class GHDeploymentBuilder {
*
* @param autoMerge
* the auto merge
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder autoMerge(boolean autoMerge) {
@@ -76,6 +82,7 @@ public class GHDeploymentBuilder {
*
* @param requiredContexts
* the required contexts
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder requiredContexts(List<String> requiredContexts) {
@@ -88,6 +95,7 @@ public class GHDeploymentBuilder {
*
* @param payload
* the payload
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder payload(String payload) {
@@ -100,6 +108,7 @@ public class GHDeploymentBuilder {
*
* @param environment
* the environment
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder environment(String environment) {
@@ -107,11 +116,47 @@ public class GHDeploymentBuilder {
return this;
}
/**
* Specifies if the given environment is specific to the deployment and will no longer exist at some point in the
* future.
*
* @deprecated until preview feature has graduated to stable
*
* @param transientEnvironment
* the environment is transient
*
* @return the gh deployment builder
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public GHDeploymentBuilder transientEnvironment(boolean transientEnvironment) {
builder.with("transient_environment", transientEnvironment);
return this;
}
/**
* Specifies if the given environment is one that end-users directly interact with.
*
* @deprecated until preview feature has graduated to stable
*
* @param productionEnvironment
* the environment is used by end-users directly
*
* @return the gh deployment builder
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public GHDeploymentBuilder productionEnvironment(boolean productionEnvironment) {
builder.with("production_environment", productionEnvironment);
return this;
}
/**
* Description gh deployment builder.
*
* @param description
* the description
*
* @return the gh deployment builder
*/
public GHDeploymentBuilder description(String description) {
@@ -123,6 +168,7 @@ public class GHDeploymentBuilder {
* Create gh deployment.
*
* @return the gh deployment
*
* @throws IOException
* the io exception
*/

View File

@@ -4,5 +4,35 @@ package org.kohsuke.github;
* Represents the state of deployment
*/
public enum GHDeploymentState {
PENDING, SUCCESS, ERROR, FAILURE
PENDING,
SUCCESS,
ERROR,
FAILURE,
/**
* The state of the deployment currently reflects it's in progress.
*
* @deprecated until preview feature has graduated to stable
*/
@Deprecated
@Preview(Previews.FLASH)
IN_PROGRESS,
/**
* The state of the deployment currently reflects it's queued up for processing.
*
* @deprecated until preview feature has graduated to stable
*/
@Deprecated
@Preview(Previews.FLASH)
QUEUED,
/**
* The state of the deployment currently reflects it's no longer active.
*
* @deprecated until preview feature has graduated to stable
*/
@Deprecated
@Preview(Previews.ANT_MAN)
INACTIVE
}

View File

@@ -13,14 +13,17 @@ public class GHDeploymentStatus extends GHObject {
protected String state;
protected String description;
protected String target_url;
protected String log_url;
protected String deployment_url;
protected String repository_url;
protected String environment_url;
/**
* Wrap gh deployment status.
*
* @param owner
* the owner
*
* @return the gh deployment status
*/
public GHDeploymentStatus wrap(GHRepository owner) {
@@ -34,12 +37,30 @@ public class GHDeploymentStatus extends GHObject {
/**
* Gets target url.
*
* @deprecated Target url is deprecated in favor of {@link #getLogUrl() getLogUrl}
*
* @return the target url
*/
@Deprecated
public URL getTargetUrl() {
return GitHubClient.parseURL(target_url);
}
/**
* Gets target url.
* <p>
* This method replaces {@link #getTargetUrl() getTargetUrl}}.
*
* @deprecated until preview feature has graduated to stable
*
* @return the target url
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public URL getLogUrl() {
return GitHubClient.parseURL(log_url);
}
/**
* Gets deployment url.
*
@@ -49,6 +70,19 @@ public class GHDeploymentStatus extends GHObject {
return GitHubClient.parseURL(deployment_url);
}
/**
* Gets deployment environment url.
*
* @deprecated until preview feature has graduated to stable
*
* @return the deployment environment url
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public URL getEnvironmentUrl() {
return GitHubClient.parseURL(environment_url);
}
/**
* Gets repository url.
*

View File

@@ -21,6 +21,7 @@ public class GHDeploymentStatusBuilder {
* the deployment id
* @param state
* the state
*
* @deprecated Use {@link GHDeployment#createStatus(GHDeploymentState)}
*/
@Deprecated
@@ -31,15 +32,38 @@ public class GHDeploymentStatusBuilder {
GHDeploymentStatusBuilder(GHRepository repo, long deploymentId, GHDeploymentState state) {
this.repo = repo;
this.deploymentId = deploymentId;
this.builder = repo.root.createRequest().method("POST");
this.builder = repo.root.createRequest()
.withPreview(Previews.ANT_MAN)
.withPreview(Previews.FLASH)
.method("POST");
this.builder.with("state", state);
}
/**
* Add an inactive status to all prior non-transient, non-production environment deployments with the same
* repository and environment name as the created status's deployment.
*
* @deprecated until preview feature has graduated to stable
*
* @param autoInactive
* Add inactive status flag
*
* @return the gh deployment status builder
*/
@Deprecated
@Preview({ Previews.ANT_MAN, Previews.FLASH })
public GHDeploymentStatusBuilder autoInactive(boolean autoInactive) {
this.builder.with("auto_inactive", autoInactive);
return this;
}
/**
* Description gh deployment status builder.
*
* @param description
* the description
*
* @return the gh deployment status builder
*/
public GHDeploymentStatusBuilder description(String description) {
@@ -47,13 +71,70 @@ public class GHDeploymentStatusBuilder {
return this;
}
/**
* Name for the target deployment environment, which can be changed when setting a deploy status.
*
* @deprecated until preview feature has graduated to stable
*
* @param environment
* the environment name
*
* @return the gh deployment status builder
*/
@Deprecated
@Preview(Previews.FLASH)
public GHDeploymentStatusBuilder environment(String environment) {
this.builder.with("environment", environment);
return this;
}
/**
* The URL for accessing the environment
*
* @deprecated until preview feature has graduated to stable
*
* @param environmentUrl
* the environment url
*
* @return the gh deployment status builder
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public GHDeploymentStatusBuilder environmentUrl(String environmentUrl) {
this.builder.with("environment_url", environmentUrl);
return this;
}
/**
* The full URL of the deployment's output.
* <p>
* This method replaces {@link #targetUrl(String) targetUrl}.
*
* @deprecated until preview feature has graduated to stable
*
* @param logUrl
* the deployment output url
*
* @return the gh deployment status builder
*/
@Deprecated
@Preview(Previews.ANT_MAN)
public GHDeploymentStatusBuilder logUrl(String logUrl) {
this.builder.with("log_url", logUrl);
return this;
}
/**
* Target url gh deployment status builder.
*
* @deprecated Target url is deprecated in favor of {@link #logUrl(String) logUrl}
*
* @param targetUrl
* the target url
*
* @return the gh deployment status builder
*/
@Deprecated
public GHDeploymentStatusBuilder targetUrl(String targetUrl) {
this.builder.with("target_url", targetUrl);
return this;
@@ -63,6 +144,7 @@ public class GHDeploymentStatusBuilder {
* Create gh deployment status.
*
* @return the gh deployment status
*
* @throws IOException
* the io exception
*/

View File

@@ -163,6 +163,8 @@ public class GHRepository extends GHObject {
.with("task", task)
.with("environment", environment)
.withUrlPath(getApiTailUrl("deployments"))
.withPreview(ANT_MAN)
.withPreview(FLASH)
.toIterable(GHDeployment[].class, item -> item.wrap(this));
}
@@ -178,6 +180,8 @@ public class GHRepository extends GHObject {
public GHDeployment getDeployment(long id) throws IOException {
return root.createRequest()
.withUrlPath(getApiTailUrl("deployments/" + id))
.withPreview(ANT_MAN)
.withPreview(FLASH)
.fetch(GHDeployment.class)
.wrap(this);
}

View File

@@ -8,11 +8,23 @@ import java.lang.annotation.RetentionPolicy;
* Indicates that the method/class/etc marked maps to GitHub API in the preview period.
* <p>
* These APIs are subject to change and not a part of the backward compatibility commitment. Always used in conjunction
* with 'deprecated' to raise awareness to clients.
* with 'deprecated' to raise awareness to clients. In addition, it's advised to update the targets documentation to
* signify that the deprecation is required until preview feature being used is promoted to stable.
*
* @author Kohsuke Kawaguchi
*/
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Preview {
/**
* An optional field defining what API media types must be set inorder to support the usage of this annotations
* target.
* <p>
* This value should be set using the existing constants defined in {@link Previews}
*
* @return The API preview media type.
*/
public String[] value() default {};
}

View File

@@ -15,6 +15,13 @@ class Previews {
*/
static final String ANTIOPE = "application/vnd.github.antiope-preview+json";
/**
* Enhanced Deployments
*
* @see <a href="https://developer.github.com/v3/previews/#enhanced-deployments">GitHub API Previews</a>
*/
static final String ANT_MAN = "application/vnd.github.ant-man-preview+json";
/**
* Create repository from template repository
*
@@ -30,6 +37,13 @@ class Previews {
*/
static final String CLOAK = "application/vnd.github.cloak-preview+json";
/**
* New deployment statuses and support for updating deployment status environment
*
* @see <a href="https://developer.github.com/v3/previews/#deployment-statuses">GitHub API Previews</a>
*/
static final String FLASH = "application/vnd.github.flash-preview+json";
/**
* Owners of GitHub Apps can now uninstall an app using the Apps API
*

View File

@@ -180,6 +180,9 @@ public class AppTest extends AbstractGitHubWireMockTest {
assertFalse(Iterables.isEmpty(deployments));
GHDeployment unitTestDeployment = deployments.get(0);
assertEquals("unittest", unitTestDeployment.getEnvironment());
assertEquals("unittest", unitTestDeployment.getOriginalEnvironment());
assertEquals(false, unitTestDeployment.isProductionEnvironment());
assertEquals(true, unitTestDeployment.isTransientEnvironment());
assertEquals("master", unitTestDeployment.getRef());
}
@@ -191,14 +194,23 @@ public class AppTest extends AbstractGitHubWireMockTest {
.description("question")
.payload("{\"user\":\"atmos\",\"room_id\":123456}")
.create();
GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.SUCCESS)
GHDeploymentStatus ghDeploymentStatus = deployment.createStatus(GHDeploymentState.QUEUED)
.description("success")
.targetUrl("http://www.github.com")
.logUrl("http://www.github.com/logurl")
.environmentUrl("http://www.github.com/envurl")
.environment("new-ci-env")
.create();
Iterable<GHDeploymentStatus> deploymentStatuses = deployment.listStatuses();
assertNotNull(deploymentStatuses);
assertEquals(1, Iterables.size(deploymentStatuses));
assertEquals(ghDeploymentStatus.getId(), Iterables.get(deploymentStatuses, 0).getId());
GHDeploymentStatus actualStatus = Iterables.get(deploymentStatuses, 0);
assertEquals(ghDeploymentStatus.getId(), actualStatus.getId());
assertEquals(ghDeploymentStatus.getState(), actualStatus.getState());
assertEquals(ghDeploymentStatus.getLogUrl(), actualStatus.getLogUrl());
// Target url was deprecated and replaced with log url. The gh api will
// prefer the log url value and return it in place of target url.
assertEquals(ghDeploymentStatus.getTargetUrl(), actualStatus.getLogUrl());
}
@Test

View File

@@ -23,6 +23,9 @@ public class GHDeploymentTest extends AbstractGitHubWireMockTest {
assertEquals("master", deployment.getRef());
assertEquals("3a09d2de4a9a1322a0ba2c3e2f54a919ca8fe353", deployment.getSha());
assertEquals("deploy", deployment.getTask());
assertEquals("production", deployment.getOriginalEnvironment());
assertEquals(false, deployment.isProductionEnvironment());
assertEquals(true, deployment.isTransientEnvironment());
}
@Test
@@ -41,6 +44,9 @@ public class GHDeploymentTest extends AbstractGitHubWireMockTest {
assertEquals("two", payload.get("custom2"));
assertEquals(Arrays.asList("3", 3, "three"), payload.get("custom3"));
assertNull(payload.get("custom4"));
assertEquals("production", deployment.getOriginalEnvironment());
assertEquals(false, deployment.isProductionEnvironment());
assertEquals(true, deployment.isTransientEnvironment());
}
protected GHRepository getRepository() throws IOException {

View File

@@ -32,5 +32,7 @@
"created_at": "2019-10-03T18:57:57Z",
"updated_at": "2019-10-03T18:57:57Z",
"statuses_url": "http://localhost:62379/repos/hub4j-test-org/github-api-test/deployments/173089055/statuses",
"repository_url": "http://localhost:62379/repos/hub4j-test-org/github-api-test"
"repository_url": "http://localhost:62379/repos/hub4j-test-org/github-api-test",
"transient_environment": true,
"production_environment": false
}

View File

@@ -33,6 +33,8 @@
"created_at": "2019-10-03T18:57:57Z",
"updated_at": "2019-10-03T18:57:57Z",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-test/deployments/173089055/statuses",
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api-test"
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api-test",
"transient_environment": true,
"production_environment": false
}
]

View File

@@ -13,7 +13,7 @@
],
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
"equalTo": "application/vnd.github.ant-man-preview+json, application/vnd.github.flash-preview+json"
}
}
},

View File

@@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
"equalTo": "application/vnd.github.ant-man-preview+json, application/vnd.github.flash-preview+json"
}
}
},

View File

@@ -37,5 +37,7 @@
"created_at": "2019-10-30T00:03:34Z",
"updated_at": "2019-10-30T00:03:34Z",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments/178653229/statuses",
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api"
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api",
"transient_environment": true,
"production_environment": false
}

View File

@@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
"equalTo": "application/vnd.github.ant-man-preview+json, application/vnd.github.flash-preview+json"
}
}
},

View File

@@ -32,5 +32,7 @@
"created_at": "2019-10-30T00:03:34Z",
"updated_at": "2019-10-30T00:03:34Z",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments/178653229/statuses",
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api"
"repository_url": "https://api.github.com/repos/hub4j-test-org/github-api",
"transient_environment": true,
"production_environment": false
}

View File

@@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
"equalTo": "application/vnd.github.ant-man-preview+json, application/vnd.github.flash-preview+json"
}
}
},