Skip to content

Commit acf1dde

Browse files
authored
Merge pull request #1660 from garridobarrera/main
New method to retrieve repo action variable
2 parents 725d1c6 + 14e609d commit acf1dde

File tree

10 files changed

+503
-0
lines changed

10 files changed

+503
-0
lines changed

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,21 @@ public GHContent getReadme() throws IOException {
27292729
return requester.withUrlPath(getApiTailUrl("readme")).fetch(GHContent.class).wrap(this);
27302730
}
27312731

2732+
/**
2733+
* Gets a variable by name
2734+
*
2735+
* @param name
2736+
* the variable name (e.g. test-variable)
2737+
* @return the variable
2738+
* @throws IOException
2739+
* the io exception
2740+
*/
2741+
public GHRepositoryVariable getRepoVariable(String name) throws IOException {
2742+
return root().createRequest()
2743+
.withUrlPath(getApiTailUrl("actions/variables"), name)
2744+
.fetch(GHRepositoryVariable.class);
2745+
}
2746+
27322747
/**
27332748
* Creates a new content, or update an existing content.
27342749
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* The type Gh repository variable.
5+
*
6+
* @author garridobarrera
7+
*/
8+
public class GHRepositoryVariable {
9+
private String name;
10+
private String value;
11+
private String createdAt;
12+
private String updatedAt;
13+
14+
/**
15+
* Gets name.
16+
*
17+
* @return the name
18+
*/
19+
public String getName() {
20+
return name;
21+
}
22+
23+
/**
24+
* Gets value.
25+
*
26+
* @return the value
27+
*/
28+
public String getValue() {
29+
return value;
30+
}
31+
}

src/test/java/org/kohsuke/github/GHRepositoryTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,4 +1581,17 @@ public void starTest() throws Exception {
15811581
repository.unstar();
15821582
assertThat(repository.listStargazers().toList().size(), is(0));
15831583
}
1584+
1585+
/**
1586+
* Test to check getRepoVariable method.
1587+
*
1588+
* @throws Exception
1589+
* the exception
1590+
*/
1591+
@Test
1592+
public void testRepoActionVariable() throws Exception {
1593+
GHRepository repository = getRepository();
1594+
GHRepositoryVariable variable = repository.getRepoVariable("myvar");
1595+
assertThat(variable.getValue(), is("this is my var value"));
1596+
}
15841597
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 59470614,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU5NDcwNjE0",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/59470614?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 1,
18+
"public_gists": 0,
19+
"followers": 8,
20+
"following": 0,
21+
"html_url": "https://github.com/hub4j-test-org",
22+
"created_at": "2020-01-03T09:09:41Z",
23+
"updated_at": "2023-05-15T08:11:52Z",
24+
"type": "Organization",
25+
"total_private_repos": 1534,
26+
"owned_private_repos": 1574,
27+
"private_gists": 0,
28+
"disk_usage": 4263895,
29+
"collaborators": 72,
30+
"billing_email": "[email protected]",
31+
"default_repository_permission": "none",
32+
"members_can_create_repositories": false,
33+
"two_factor_requirement_enabled": false,
34+
"members_allowed_repository_creation_type": "none",
35+
"members_can_create_public_repositories": false,
36+
"members_can_create_private_repositories": false,
37+
"members_can_create_internal_repositories": false,
38+
"members_can_create_pages": true,
39+
"members_can_fork_private_repositories": false,
40+
"web_commit_signoff_required": false,
41+
"members_can_create_public_pages": true,
42+
"members_can_create_private_pages": true,
43+
"plan": {
44+
"name": "enterprise",
45+
"space": 976562499,
46+
"private_repos": 999999,
47+
"filled_seats": 5072,
48+
"seats": 5664
49+
},
50+
"advanced_security_enabled_for_new_repositories": false,
51+
"dependabot_alerts_enabled_for_new_repositories": false,
52+
"dependabot_security_updates_enabled_for_new_repositories": false,
53+
"dependency_graph_enabled_for_new_repositories": false,
54+
"secret_scanning_enabled_for_new_repositories": false,
55+
"secret_scanning_push_protection_enabled_for_new_repositories": false,
56+
"secret_scanning_push_protection_custom_link_enabled": false,
57+
"secret_scanning_push_protection_custom_link": null
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"id": 317839899,
3+
"node_id": "MDEwOlJlcG9zaXRvcnkzMTc4Mzk4OTk=",
4+
"name": "github-api",
5+
"full_name": "hub4j-test-org/github-api",
6+
"private": true,
7+
"owner": {
8+
"login": "hub4j-test-org",
9+
"id": 59470614,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU5NDcwNjE0",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/59470614?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j-test-org",
14+
"html_url": "https://github.com/hub4j-test-org",
15+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
16+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
22+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j-test-org/github-api",
28+
"description": null,
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j-test-org/github-api",
31+
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j-test-org/github-api/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j-test-org/github-api/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j-test-org/github-api/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j-test-org/github-api/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api/contributors",
49+
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j-test-org/github-api/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j-test-org/github-api/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j-test-org/github-api/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments",
67+
"created_at": "2020-12-02T11:25:38Z",
68+
"updated_at": "2022-06-10T11:48:11Z",
69+
"pushed_at": "2023-05-15T10:30:23Z",
70+
"git_url": "git://github.com/hub4j-test-org/github-api.git",
71+
"ssh_url": "[email protected]:hub4j-test-org/github-api.git",
72+
"clone_url": "https://github.com/hub4j-test-org/github-api.git",
73+
"svn_url": "https://github.com/hub4j-test-org/github-api",
74+
"homepage": null,
75+
"size": 15775,
76+
"stargazers_count": 0,
77+
"watchers_count": 0,
78+
"language": null,
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": false,
84+
"has_discussions": true,
85+
"forks_count": 0,
86+
"mirror_url": null,
87+
"archived": false,
88+
"disabled": false,
89+
"open_issues_count": 358,
90+
"license": null,
91+
"allow_forking": false,
92+
"is_template": false,
93+
"web_commit_signoff_required": false,
94+
"topics": [],
95+
"visibility": "private",
96+
"forks": 0,
97+
"open_issues": 358,
98+
"watchers": 0,
99+
"default_branch": "main",
100+
"permissions": {
101+
"admin": true,
102+
"maintain": true,
103+
"push": true,
104+
"triage": true,
105+
"pull": true
106+
},
107+
"temp_clone_token": "ABVSGFSHJP3EZB4Y6UK2PQLEMIMI2",
108+
"allow_squash_merge": true,
109+
"allow_merge_commit": true,
110+
"allow_rebase_merge": true,
111+
"allow_auto_merge": false,
112+
"delete_branch_on_merge": true,
113+
"allow_update_branch": false,
114+
"use_squash_pr_title_as_default": false,
115+
"squash_merge_commit_message": "COMMIT_MESSAGES",
116+
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
117+
"merge_commit_message": "PR_TITLE",
118+
"merge_commit_title": "MERGE_MESSAGE",
119+
"organization": {
120+
"login": "hub4j-test-org",
121+
"id": 59470614,
122+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU5NDcwNjE0",
123+
"avatar_url": "https://avatars.githubusercontent.com/u/59470614?v=4",
124+
"gravatar_id": "",
125+
"url": "https://api.github.com/users/hub4j-test-org",
126+
"html_url": "https://github.com/hub4j-test-org",
127+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
128+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
129+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
130+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
131+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
132+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
133+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
134+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
135+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
136+
"type": "Organization",
137+
"site_admin": false
138+
},
139+
"network_count": 0,
140+
"subscribers_count": 5
141+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "garridobarrera",
3+
"id": 7021334,
4+
"node_id": "MDQ6VXNlcjcwMjEzMzQ=",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/7021334?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/garridobarrera",
8+
"html_url": "https://github.com/garridobarrera",
9+
"followers_url": "https://api.github.com/users/garridobarrera/followers",
10+
"following_url": "https://api.github.com/users/garridobarrera/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/garridobarrera/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/garridobarrera/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/garridobarrera/subscriptions",
14+
"organizations_url": "https://api.github.com/users/garridobarrera/orgs",
15+
"repos_url": "https://api.github.com/users/garridobarrera/repos",
16+
"events_url": "https://api.github.com/users/garridobarrera/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/garridobarrera/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "José Manuel Garrido Barrera",
21+
"company": "personal",
22+
"blog": "",
23+
"location": null,
24+
"email": "[email protected]",
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 11,
29+
"public_gists": 0,
30+
"followers": 3,
31+
"following": 2,
32+
"created_at": "2014-03-21T10:37:00Z",
33+
"updated_at": "2023-03-13T11:32:23Z",
34+
"private_gists": 0,
35+
"total_private_repos": 2,
36+
"owned_private_repos": 2,
37+
"disk_usage": 5935,
38+
"collaborators": 1,
39+
"two_factor_authentication": true,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"id": "6831ee08-d197-4e72-b2b7-9b4c97997f3a",
3+
"name": "orgs_hub4j-test-org",
4+
"request": {
5+
"url": "/orgs/hub4j-test-org",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.v3+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "orgs_hub4j-test-org-2.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Mon, 15 May 2023 11:28:33 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"210fe7604fbf3cb73c20f3bc9dd95de3c73e21a0d2951bd667321d59e920633f\"",
26+
"Last-Modified": "Mon, 15 May 2023 08:11:52 GMT",
27+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
28+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
29+
"X-GitHub-Media-Type": "github.v3; format=json",
30+
"x-github-api-version-selected": "2022-11-28",
31+
"X-RateLimit-Limit": "5000",
32+
"X-RateLimit-Remaining": "4804",
33+
"X-RateLimit-Reset": "1684151924",
34+
"X-RateLimit-Used": "196",
35+
"X-RateLimit-Resource": "core",
36+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
37+
"Access-Control-Allow-Origin": "*",
38+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
39+
"X-Frame-Options": "deny",
40+
"X-Content-Type-Options": "nosniff",
41+
"X-XSS-Protection": "0",
42+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
43+
"Content-Security-Policy": "default-src 'none'",
44+
"X-GitHub-Request-Id": "F3A4:B316:162B7156:1665F336:64621760"
45+
}
46+
},
47+
"uuid": "6831ee08-d197-4e72-b2b7-9b4c97997f3a",
48+
"persistent": true,
49+
"insertionIndex": 2
50+
}

0 commit comments

Comments
 (0)