Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to list workflow runs by head sha and created date #1789

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
28 changes: 28 additions & 0 deletions src/main/java/org/kohsuke/github/GHWorkflowRunQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ public GHWorkflowRunQueryBuilder conclusion(Conclusion conclusion) {
return this;
}

/**
* Created workflow run query builder.
*
* @param created
* a range following the Query for dates syntax
*
* @return the gh workflow run query builder
* @see <a href=
* "https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax#query-for-dates">Query
* for dates</a>
*/
public GHWorkflowRunQueryBuilder created(String created) {
req.with("created", created);
return this;
}

/**
* Head sha workflow run query builder.
*
* @param headSha
* the head sha
* @return the gh workflow run query builder
*/
public GHWorkflowRunQueryBuilder headSha(String headSha) {
req.with("head_sha", headSha);
return this;
}

/**
* List.
*
Expand Down
71 changes: 71 additions & 0 deletions src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
Expand Down Expand Up @@ -232,6 +234,75 @@ public void testSearchOnBranch() throws IOException {
assertThat(workflowRun.getConclusion(), equalTo(Conclusion.SUCCESS));
}

/**
* Test search on created and head sha.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testSearchOnCreatedAndHeadSha() throws IOException {
GHWorkflow workflow = repo.getWorkflow(FAST_WORKFLOW_PATH);

long latestPreexistingWorkflowRunId = getLatestPreexistingWorkflowRunId();

Instant before = Instant.parse("2024-02-09T10:19:00.00Z");

String mainBranchHeadSha = repo.getBranch(MAIN_BRANCH).getSHA1();
String secondBranchHeadSha = repo.getBranch(SECOND_BRANCH).getSHA1();

workflow.dispatch(MAIN_BRANCH);
workflow.dispatch(SECOND_BRANCH);

await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
FAST_WORKFLOW_NAME,
MAIN_BRANCH,
Status.COMPLETED,
latestPreexistingWorkflowRunId).isPresent());
await((nonRecordingRepo) -> getWorkflowRun(nonRecordingRepo,
FAST_WORKFLOW_NAME,
SECOND_BRANCH,
Status.COMPLETED,
latestPreexistingWorkflowRunId).isPresent());

List<GHWorkflowRun> mainBranchHeadShaWorkflowRuns = repo.queryWorkflowRuns()
.headSha(mainBranchHeadSha)
.created(">=" + before.toString())
.list()
.toList();
List<GHWorkflowRun> secondBranchHeadShaWorkflowRuns = repo.queryWorkflowRuns()
.headSha(secondBranchHeadSha)
.created(">=" + before.toString())
.list()
.toList();

assertThat(mainBranchHeadShaWorkflowRuns, hasSize(greaterThanOrEqualTo(1)));
assertThat(mainBranchHeadShaWorkflowRuns, everyItem(hasProperty("headSha", equalTo(mainBranchHeadSha))));
// Ideally, we would use everyItem() but the bridge method is in the way
for (GHWorkflowRun workflowRun : mainBranchHeadShaWorkflowRuns) {
assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(Date.from(before)));
}

assertThat(secondBranchHeadShaWorkflowRuns, hasSize(greaterThanOrEqualTo(1)));
assertThat(secondBranchHeadShaWorkflowRuns, everyItem(hasProperty("headSha", equalTo(secondBranchHeadSha))));
// Ideally, we would use everyItem() but the bridge method is in the way
for (GHWorkflowRun workflowRun : secondBranchHeadShaWorkflowRuns) {
assertThat(workflowRun.getCreatedAt(), greaterThanOrEqualTo(Date.from(before)));
}

List<GHWorkflowRun> mainBranchHeadShaWorkflowRunsBefore = repo.queryWorkflowRuns()
.headSha(repo.getBranch(MAIN_BRANCH).getSHA1())
.created("<" + before.toString())
.list()
.toList();
// Ideally, we would use that but the bridge method is causing issues
// assertThat(mainBranchHeadShaWorkflowRunsBefore, everyItem(hasProperty("createdAt",
// lessThan(Date.from(before)))));
for (GHWorkflowRun workflowRun : mainBranchHeadShaWorkflowRunsBefore) {
assertThat(workflowRun.getCreatedAt(), lessThan(Date.from(before)));
}
}

/**
* Test logs.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"id": 348674220,
"node_id": "MDEwOlJlcG9zaXRvcnkzNDg2NzQyMjA=",
"name": "GHWorkflowRunTest",
"full_name": "hub4j-test-org/GHWorkflowRunTest",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest",
"description": "Repository used by GHWorkflowRunTest",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest",
"forks_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/deployments",
"created_at": "2021-03-17T10:50:49Z",
"updated_at": "2023-11-08T21:14:03Z",
"pushed_at": "2023-11-08T21:53:11Z",
"git_url": "git://github.com/hub4j-test-org/GHWorkflowRunTest.git",
"ssh_url": "git@github.com:hub4j-test-org/GHWorkflowRunTest.git",
"clone_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest.git",
"svn_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest",
"homepage": null,
"size": 12,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 1,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 7,
"license": null,
"allow_forking": true,
"is_template": false,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 1,
"open_issues": 7,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"use_squash_pr_title_as_default": false,
"squash_merge_commit_message": "COMMIT_MESSAGES",
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
"merge_commit_message": "PR_TITLE",
"merge_commit_title": "MERGE_MESSAGE",
"custom_properties": {},
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"site_admin": false
},
"security_and_analysis": {
"secret_scanning": {
"status": "disabled"
},
"secret_scanning_push_protection": {
"status": "disabled"
},
"dependabot_security_updates": {
"status": "disabled"
},
"secret_scanning_validity_checks": {
"status": "disabled"
}
},
"network_count": 1,
"subscribers_count": 10
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"name": "main",
"commit": {
"sha": "e8b2761bda453495d1ae25941b5b380b07deae52",
"node_id": "C_kwDOFMhYrNoAKGU4YjI3NjFiZGE0NTM0OTVkMWFlMjU5NDFiNWIzODBiMDdkZWFlNTI",
"commit": {
"author": {
"name": "Yasin Herken",
"email": "57527891+yasin-herken@users.noreply.github.com",
"date": "2023-11-08T21:53:11Z"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com",
"date": "2023-11-08T21:53:11Z"
},
"message": "Update startup-failure-workflow.yml\n\nChanging workflow to get startup-failure",
"tree": {
"sha": "e67e0a5e6ffd0894c412d2aad46196c849c0803b",
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/trees/e67e0a5e6ffd0894c412d2aad46196c849c0803b"
},
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/git/commits/e8b2761bda453495d1ae25941b5b380b07deae52",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJlTANHCRBK7hj4Ov3rIwAAk3sIAES3J69Uym48L0fZi1MFaErd\nUsFLU+OHvSzY7KQMreUiK9N5zvcj3NsnMEDxCJtMP5s4siyvqPHO8uIGcy/wqgYT\nBMiA/Uf8hNFNvCNtHleTkbZyAqcVdFn4LQ2ffHAWugc7xJwUnEmawXCaSJG+D+CA\nXjBEhi4xbq5YJKIt40cK7FnApn+YItauDzqJgyIxR+WwCM/KryvpUDWhpjzrT6Bs\npNXXmGTXjjkv5VEDyRUja8DjuXW/PNO16tWE0XMMy2lgnZjYCnwceTvmrujzM4bo\nFj3QDoYMQwp+ZXc87zNl2Hdj2rvAkqU1uXN6Hck1uCMvt4ObC5AIZ1bn15pGqKw=\n=Hokl\n-----END PGP SIGNATURE-----\n",
"payload": "tree e67e0a5e6ffd0894c412d2aad46196c849c0803b\nparent 3c712d0b18d9313f69c0d96b9d0a6fd9421203d2\nauthor Yasin Herken <57527891+yasin-herken@users.noreply.github.com> 1699480391 +0300\ncommitter GitHub <noreply@github.com> 1699480391 +0300\n\nUpdate startup-failure-workflow.yml\n\nChanging workflow to get startup-failure"
}
},
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/commits/e8b2761bda453495d1ae25941b5b380b07deae52",
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/commit/e8b2761bda453495d1ae25941b5b380b07deae52",
"comments_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/commits/e8b2761bda453495d1ae25941b5b380b07deae52/comments",
"author": {
"login": "yasin-herken",
"id": 57527891,
"node_id": "MDQ6VXNlcjU3NTI3ODkx",
"avatar_url": "https://avatars.githubusercontent.com/u/57527891?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/yasin-herken",
"html_url": "https://github.com/yasin-herken",
"followers_url": "https://api.github.com/users/yasin-herken/followers",
"following_url": "https://api.github.com/users/yasin-herken/following{/other_user}",
"gists_url": "https://api.github.com/users/yasin-herken/gists{/gist_id}",
"starred_url": "https://api.github.com/users/yasin-herken/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/yasin-herken/subscriptions",
"organizations_url": "https://api.github.com/users/yasin-herken/orgs",
"repos_url": "https://api.github.com/users/yasin-herken/repos",
"events_url": "https://api.github.com/users/yasin-herken/events{/privacy}",
"received_events_url": "https://api.github.com/users/yasin-herken/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "web-flow",
"id": 19864447,
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
"avatar_url": "https://avatars.githubusercontent.com/u/19864447?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/web-flow",
"html_url": "https://github.com/web-flow",
"followers_url": "https://api.github.com/users/web-flow/followers",
"following_url": "https://api.github.com/users/web-flow/following{/other_user}",
"gists_url": "https://api.github.com/users/web-flow/gists{/gist_id}",
"starred_url": "https://api.github.com/users/web-flow/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/web-flow/subscriptions",
"organizations_url": "https://api.github.com/users/web-flow/orgs",
"repos_url": "https://api.github.com/users/web-flow/repos",
"events_url": "https://api.github.com/users/web-flow/events{/privacy}",
"received_events_url": "https://api.github.com/users/web-flow/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "3c712d0b18d9313f69c0d96b9d0a6fd9421203d2",
"url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/commits/3c712d0b18d9313f69c0d96b9d0a6fd9421203d2",
"html_url": "https://github.com/hub4j-test-org/GHWorkflowRunTest/commit/3c712d0b18d9313f69c0d96b9d0a6fd9421203d2"
}
]
},
"_links": {
"self": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/branches/main",
"html": "https://github.com/hub4j-test-org/GHWorkflowRunTest/tree/main"
},
"protected": false,
"protection": {
"enabled": false,
"required_status_checks": {
"enforcement_level": "off",
"contexts": [],
"checks": []
}
},
"protection_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/branches/main/protection"
}
Loading
Loading