Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions src/main/java/org/kohsuke/github/GHLabel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.kohsuke.github;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -13,7 +15,7 @@
* @see GHIssue#getLabels() GHIssue#getLabels()
* @see GHRepository#listLabels() GHRepository#listLabels()
*/
public class GHLabel {
public class GHLabel extends GHObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually have all the fields from GHObject? I don't think it does.

private String url, name, color, description;
private GHRepository repo;

Expand All @@ -22,8 +24,18 @@ public class GHLabel {
*
* @return the url
*/
public String getUrl() {
return url;
public URL getUrl() {
try {
return new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}

@Override
public URL getHtmlUrl() throws IOException {
return null;
}

/**
Expand Down Expand Up @@ -68,6 +80,25 @@ public void delete() throws IOException {
repo.root.createRequest().method("DELETE").setRawUrlPath(url).send();
}

/**
* Sets color.
*
* @param newName
* New name
* @throws IOException
* the io exception
*/
public void setName(String newName) throws IOException {
repo.root.createRequest()
.method("PATCH")
.with("new_name", newName)
.with("color", color)
.with("description", description)
.setRawUrlPath(url)
.fetchInto(this)
.wrapUp(this.repo);
}

/**
* Sets color.
*
Expand All @@ -83,7 +114,8 @@ public void setColor(String newColor) throws IOException {
.with("color", newColor)
.with("description", description)
.setRawUrlPath(url)
.send();
.fetchInto(this)
.wrapUp(this.repo);
}

/**
Expand All @@ -101,7 +133,8 @@ public void setDescription(String newDescription) throws IOException {
.with("color", color)
.with("description", newDescription)
.setRawUrlPath(url)
.send();
.fetchInto(this)
.wrapUp(this.repo);
}

static Collection<String> toNames(Collection<GHLabel> labels) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ public GHLabel createLabel(String name, String color) throws IOException {
}

/**
* Description is still in preview.
* Creates a new github label
*
* @param name
* the name
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/kohsuke/github/GHLabelTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.kohsuke.github;

import org.junit.Test;

import java.util.List;

import static org.hamcrest.Matchers.*;

public class GHLabelTest extends org.kohsuke.github.AbstractGitHubWireMockTest {

@Test
public void test_toString() throws Exception {
GHRepository rep = getTempRepository();

GHLabel label = rep.createLabel("foo", "001122", "test foo label");
assertThat(label.toString(), containsString("name=foo,color=001122,description=test foo label"));

List<GHLabel> list = rep.listLabels().asList();

assertEquals(10, list.size());
assertThat(list.stream().filter(l -> "foo".equals(l.getName())).findAny().toString(),
containsString("name=foo,color=001122,description=test foo label"));
}

@Test
public void test_create_updateLabel() throws Exception {
GHRepository rep = getTempRepository();

GHLabel label = rep.createLabel("foo", "001122", "test foo label");
assertThat(label.toString(), containsString("name=foo,color=001122,description=test foo label"));
label.setColor("221100");
assertThat(label.toString(), containsString("name=foo,color=221100,description=test foo label"));
label.setDescription("label foo test");
assertThat(label.toString(), containsString("name=foo,color=221100,description=label foo test"));
label.setName("newfoo");
assertThat(label.toString(), containsString("name=newfoo,color=221100,description=label foo test"));
label.delete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"id": 229521552,
"node_id": "MDEwOlJlcG9zaXRvcnkyMjk1MjE1NTI=",
"name": "temp-test_create_updateLabel",
"full_name": "github-api-test-org/temp-test_create_updateLabel",
"private": false,
"owner": {
"login": "github-api-test-org",
"id": 59067752,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU5MDY3NzUy",
"avatar_url": "https://avatars3.githubusercontent.com/u/59067752?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api-test-org",
"html_url": "https://github.com/github-api-test-org",
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/github-api-test-org/temp-test_create_updateLabel",
"description": "A test repository for testing the github-api project: temp-test_create_updateLabel",
"fork": false,
"url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel",
"forks_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/forks",
"keys_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/teams",
"hooks_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/hooks",
"issue_events_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/issues/events{/number}",
"events_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/events",
"assignees_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/assignees{/user}",
"branches_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/branches{/branch}",
"tags_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/tags",
"blobs_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/statuses/{sha}",
"languages_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/languages",
"stargazers_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/stargazers",
"contributors_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/contributors",
"subscribers_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/subscribers",
"subscription_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/subscription",
"commits_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/contents/{+path}",
"compare_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/merges",
"archive_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/downloads",
"issues_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/issues{/number}",
"pulls_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/pulls{/number}",
"milestones_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/milestones{/number}",
"notifications_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/labels{/name}",
"releases_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/releases{/id}",
"deployments_url": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/deployments",
"created_at": "2019-12-22T05:15:08Z",
"updated_at": "2019-12-22T05:15:12Z",
"pushed_at": "2019-12-22T05:15:10Z",
"git_url": "git://github.com/github-api-test-org/temp-test_create_updateLabel.git",
"ssh_url": "git@github.com:github-api-test-org/temp-test_create_updateLabel.git",
"clone_url": "https://github.com/github-api-test-org/temp-test_create_updateLabel.git",
"svn_url": "https://github.com/github-api-test-org/temp-test_create_updateLabel",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"organization": {
"login": "github-api-test-org",
"id": 59067752,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU5MDY3NzUy",
"avatar_url": "https://avatars3.githubusercontent.com/u/59067752?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/github-api-test-org",
"html_url": "https://github.com/github-api-test-org",
"followers_url": "https://api.github.com/users/github-api-test-org/followers",
"following_url": "https://api.github.com/users/github-api-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/github-api-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/github-api-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/github-api-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/github-api-test-org/orgs",
"repos_url": "https://api.github.com/users/github-api-test-org/repos",
"events_url": "https://api.github.com/users/github-api-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/github-api-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"network_count": 0,
"subscribers_count": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "2d5e62d8-cef9-442b-8879-9252605af926",
"name": "repos_github-api-test-org_temp-test_create_updatelabel",
"request": {
"url": "/repos/github-api-test-org/temp-test_create_updateLabel",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "repos_github-api-test-org_temp-test_create_updatelabel-2d5e62d8-cef9-442b-8879-9252605af926.json",
"headers": {
"Server": "GitHub.com",
"Date": "Sun, 22 Dec 2019 05:15:13 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4985",
"X-RateLimit-Reset": "1576995265",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "W/\"54c7fcda570458797658b96702bc16f2\"",
"Last-Modified": "Sun, 22 Dec 2019 05:15:12 GMT",
"X-OAuth-Scopes": "admin:org, delete_repo, repo",
"X-Accepted-OAuth-Scopes": "repo",
"X-GitHub-Media-Type": "unknown, github.v3",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "3ADE:1E30:1325DC:2DC828:5DFEFBE1"
}
},
"uuid": "2d5e62d8-cef9-442b-8879-9252605af926",
"persistent": true,
"insertionIndex": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"id": "d658ff9c-bd98-46c0-aaca-d619064496ea",
"name": "repos_github-api-test-org_temp-test_create_updatelabel_labels",
"request": {
"url": "/repos/github-api-test-org/temp-test_create_updateLabel/labels",
"method": "POST",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
},
"bodyPatterns": [
{
"equalToJson": "{\"color\":\"001122\",\"name\":\"foo\",\"description\":\"test foo label\"}",
"ignoreArrayOrder": true,
"ignoreExtraElements": true
}
]
},
"response": {
"status": 201,
"body": "{\"id\":1747637599,\"node_id\":\"MDU6TGFiZWwxNzQ3NjM3NTk5\",\"url\":\"https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/labels/foo\",\"name\":\"foo\",\"color\":\"001122\",\"default\":false,\"description\":\"test foo label\"}",
"headers": {
"Server": "GitHub.com",
"Date": "Sun, 22 Dec 2019 05:15:14 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "201 Created",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4984",
"X-RateLimit-Reset": "1576995265",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "\"df88c3c4db6b74f449a6a56e27725cc4\"",
"X-OAuth-Scopes": "admin:org, delete_repo, repo",
"X-Accepted-OAuth-Scopes": "",
"Location": "https://api.github.com/repos/github-api-test-org/temp-test_create_updateLabel/labels/foo",
"X-GitHub-Media-Type": "unknown, github.v3",
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
"Access-Control-Allow-Origin": "*",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options": "deny",
"X-Content-Type-Options": "nosniff",
"X-XSS-Protection": "1; mode=block",
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy": "default-src 'none'",
"X-GitHub-Request-Id": "3ADE:1E30:1325DF:2DC82A:5DFEFBE1"
}
},
"uuid": "d658ff9c-bd98-46c0-aaca-d619064496ea",
"persistent": true,
"insertionIndex": 2
}
Loading