From bc47a48df6108fd44374954f3a1f4b60390b1dc4 Mon Sep 17 00:00:00 2001 From: ksaleschus <katrin.saleschus@qube.ag> Date: Wed, 6 Nov 2024 16:43:14 +0100 Subject: [PATCH 1/5] add getPersonalAccessToken --- .../gitlab4j/api/PersonalAccessTokenApi.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java index 323a1a027..c766ed92a 100644 --- a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java +++ b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java @@ -64,4 +64,32 @@ public PersonalAccessToken rotatePersonalAccessToken(String id, Date expiresAt) Response response = post(Response.Status.OK, formData, "personal_access_tokens", id, "rotate"); return (response.readEntity(PersonalAccessToken.class)); } + + /** + * Get information about a given access token. + * Only working with GitLab 16.0 and above. + * + * <pre><code>GitLab Endpoint: POST /personal_access_tokens/self</code></pre> + * + * @return the newly created PersonalAccessToken. + * @throws GitLabApiException if any exception occurs + */ + public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException { + return getPersonalAccessToken("self"); + } + + /** + * Get a specific personal access token. + * Only working with GitLab 16.0 and above. + * + * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id</code></pre> + * + * @param id ID of the personal access token + * @return the specified PersonalAccessToken. + * @throws GitLabApiException if any exception occurs + */ + public PersonalAccessToken getPersonalAccessToken(String id) throws GitLabApiException { + Response response = get(Response.Status.OK, null, "personal_access_tokens", id); + return (response.readEntity(PersonalAccessToken.class)); + } } From eb8c017fb369e7d8012b2ec5d43447dca497fdd2 Mon Sep 17 00:00:00 2001 From: ksaleschus <katrin.saleschus@qube.ag> Date: Wed, 6 Nov 2024 16:43:49 +0100 Subject: [PATCH 2/5] adjust commentary --- .../java/org/gitlab4j/api/PersonalAccessTokenApi.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java index c766ed92a..b0fa8a4e5 100644 --- a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java +++ b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java @@ -34,7 +34,7 @@ public PersonalAccessToken rotatePersonalAccessToken() throws GitLabApiException /** * Rotates the given personal access token. - * The token is revoked and a new one which will expire in one week is created to replace it. + * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it. * Only working with GitLab 16.0 and above. * * <pre><code>GitLab Endpoint: POST /personal_access_tokens/self/rotate</code></pre> @@ -48,12 +48,13 @@ public PersonalAccessToken rotatePersonalAccessToken(Date expiresAt) throws GitL } /** - * Rotates the given personal access token. - * The token is revoked and a new one which will expire in one week is created to replace it. + * Rotates a specific personal access token. + * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it. * Only working with GitLab 16.0 and above. * - * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id/rotate</code></pre> + * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id</code></pre> * + * @param id ID of the personal access token * @param expiresAt Expiration date of the access token * @return the newly created PersonalAccessToken. * @throws GitLabApiException if any exception occurs From a1492ed60e4a74996594e32cb38cfa6b43e2c39e Mon Sep 17 00:00:00 2001 From: ksaleschus <katrin.saleschus@qube.ag> Date: Thu, 7 Nov 2024 08:36:13 +0100 Subject: [PATCH 3/5] adjust commentary --- .../org/gitlab4j/api/PersonalAccessTokenApi.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java index b0fa8a4e5..2b77cc401 100644 --- a/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java +++ b/src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java @@ -33,7 +33,7 @@ public PersonalAccessToken rotatePersonalAccessToken() throws GitLabApiException } /** - * Rotates the given personal access token. + * Rotates the personal access token used in the request header. * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it. * Only working with GitLab 16.0 and above. * @@ -52,7 +52,7 @@ public PersonalAccessToken rotatePersonalAccessToken(Date expiresAt) throws GitL * The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it. * Only working with GitLab 16.0 and above. * - * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id</code></pre> + * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id/rotate</code></pre> * * @param id ID of the personal access token * @param expiresAt Expiration date of the access token @@ -67,12 +67,12 @@ public PersonalAccessToken rotatePersonalAccessToken(String id, Date expiresAt) } /** - * Get information about a given access token. + * Get information about the personal access token used in the request header. * Only working with GitLab 16.0 and above. * - * <pre><code>GitLab Endpoint: POST /personal_access_tokens/self</code></pre> + * <pre><code>GitLab Endpoint: GET /personal_access_tokens/self</code></pre> * - * @return the newly created PersonalAccessToken. + * @return the specified PersonalAccessToken. * @throws GitLabApiException if any exception occurs */ public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException { @@ -83,7 +83,7 @@ public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException { * Get a specific personal access token. * Only working with GitLab 16.0 and above. * - * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id</code></pre> + * <pre><code>GitLab Endpoint: GET /personal_access_tokens/:id</code></pre> * * @param id ID of the personal access token * @return the specified PersonalAccessToken. @@ -91,6 +91,6 @@ public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException { */ public PersonalAccessToken getPersonalAccessToken(String id) throws GitLabApiException { Response response = get(Response.Status.OK, null, "personal_access_tokens", id); - return (response.readEntity(PersonalAccessToken.class)); + return (response.readEntity(PersonalAccessToken.class)); } } From da45db8c2cb2d06db85df9b679ebc028dda45888 Mon Sep 17 00:00:00 2001 From: ksaleschus <katrin.saleschus@qube.ag> Date: Thu, 7 Nov 2024 09:47:03 +0100 Subject: [PATCH 4/5] add tests --- .../org/gitlab4j/api/TestGitLabApiEvents.java | 6 +++ .../org/gitlab4j/api/deployment-event.json | 37 +++++++++++++++++++ .../org/gitlab4j/api/environment.json | 1 + 3 files changed, 44 insertions(+) create mode 100644 src/test/resources/org/gitlab4j/api/deployment-event.json diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java b/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java index 215fd7975..822e35e34 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java @@ -65,6 +65,12 @@ public static void teardown() { GitLabApi.getLogger().setLevel(savedLevel); } + @Test + public void testDeploymentEvent() throws Exception { + Event event = unmarshalResource(PipelineEvent.class, "deployment-event.json"); + assertTrue(compareJson(event, "deployment-event.json")); + } + @Test public void testIssueEvent() throws Exception { diff --git a/src/test/resources/org/gitlab4j/api/deployment-event.json b/src/test/resources/org/gitlab4j/api/deployment-event.json new file mode 100644 index 000000000..809fbe8d1 --- /dev/null +++ b/src/test/resources/org/gitlab4j/api/deployment-event.json @@ -0,0 +1,37 @@ +{ + "object_kind": "deployment", + "status": "success", + "status_changed_at":"2021-04-28 21:50:00 +0200", + "deployable_id": 796, + "deployable_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/jobs/796", + "environment": "staging", + "project": { + "id": 30, + "name": "test-deployment-webhooks", + "description": "", + "web_url": "http://10.126.0.2:3000/root/test-deployment-webhooks", + "avatar_url": null, + "git_ssh_url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", + "git_http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git", + "namespace": "Administrator", + "visibility_level": 0, + "path_with_namespace": "root/test-deployment-webhooks", + "default_branch": "master", + "ci_config_path": "", + "homepage": "http://10.126.0.2:3000/root/test-deployment-webhooks", + "url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", + "ssh_url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", + "http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git" + }, + "short_sha": "279484c0", + "user": { + "id": 1, + "name": "Administrator", + "username": "root", + "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", + "email": "admin@example.com" + }, + "user_url": "http://10.126.0.2:3000/root", + "commit_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/commit/279484c09fbe69ededfced8c1bb6e6d24616b468", + "commit_title": "Add new file" +} diff --git a/src/test/resources/org/gitlab4j/api/environment.json b/src/test/resources/org/gitlab4j/api/environment.json index ff77773da..9d2de785d 100644 --- a/src/test/resources/org/gitlab4j/api/environment.json +++ b/src/test/resources/org/gitlab4j/api/environment.json @@ -5,6 +5,7 @@ "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com", "state": "available", "tier": "testing", + "auto_stop_at": "2024-11-27T13:34:49.812+01:00", "last_deployment": { "id": 100, "iid": 34, From 8e3f9f7b93b8293b24fc16d34fd425e3f6f32dac Mon Sep 17 00:00:00 2001 From: ksaleschus <katrin.saleschus@qube.ag> Date: Thu, 7 Nov 2024 09:51:05 +0100 Subject: [PATCH 5/5] Revert "add tests" This reverts commit da45db8c2cb2d06db85df9b679ebc028dda45888. --- .../org/gitlab4j/api/TestGitLabApiEvents.java | 6 --- .../org/gitlab4j/api/deployment-event.json | 37 ------------------- .../org/gitlab4j/api/environment.json | 1 - 3 files changed, 44 deletions(-) delete mode 100644 src/test/resources/org/gitlab4j/api/deployment-event.json diff --git a/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java b/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java index 822e35e34..215fd7975 100644 --- a/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java +++ b/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java @@ -65,12 +65,6 @@ public static void teardown() { GitLabApi.getLogger().setLevel(savedLevel); } - @Test - public void testDeploymentEvent() throws Exception { - Event event = unmarshalResource(PipelineEvent.class, "deployment-event.json"); - assertTrue(compareJson(event, "deployment-event.json")); - } - @Test public void testIssueEvent() throws Exception { diff --git a/src/test/resources/org/gitlab4j/api/deployment-event.json b/src/test/resources/org/gitlab4j/api/deployment-event.json deleted file mode 100644 index 809fbe8d1..000000000 --- a/src/test/resources/org/gitlab4j/api/deployment-event.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "object_kind": "deployment", - "status": "success", - "status_changed_at":"2021-04-28 21:50:00 +0200", - "deployable_id": 796, - "deployable_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/jobs/796", - "environment": "staging", - "project": { - "id": 30, - "name": "test-deployment-webhooks", - "description": "", - "web_url": "http://10.126.0.2:3000/root/test-deployment-webhooks", - "avatar_url": null, - "git_ssh_url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", - "git_http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git", - "namespace": "Administrator", - "visibility_level": 0, - "path_with_namespace": "root/test-deployment-webhooks", - "default_branch": "master", - "ci_config_path": "", - "homepage": "http://10.126.0.2:3000/root/test-deployment-webhooks", - "url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", - "ssh_url": "ssh://vlad@10.126.0.2:2222/root/test-deployment-webhooks.git", - "http_url": "http://10.126.0.2:3000/root/test-deployment-webhooks.git" - }, - "short_sha": "279484c0", - "user": { - "id": 1, - "name": "Administrator", - "username": "root", - "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", - "email": "admin@example.com" - }, - "user_url": "http://10.126.0.2:3000/root", - "commit_url": "http://10.126.0.2:3000/root/test-deployment-webhooks/-/commit/279484c09fbe69ededfced8c1bb6e6d24616b468", - "commit_title": "Add new file" -} diff --git a/src/test/resources/org/gitlab4j/api/environment.json b/src/test/resources/org/gitlab4j/api/environment.json index 9d2de785d..ff77773da 100644 --- a/src/test/resources/org/gitlab4j/api/environment.json +++ b/src/test/resources/org/gitlab4j/api/environment.json @@ -5,7 +5,6 @@ "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com", "state": "available", "tier": "testing", - "auto_stop_at": "2024-11-27T13:34:49.812+01:00", "last_deployment": { "id": 100, "iid": 34,