Repository: hub4j/github-api
Pull request #2006 (2025-01-08 19:55:49)

Include triggering actor in workflow run
# Description
Adds `triggeringActor` to GHWorkflowRun
See response object -> https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-repository

Being able to display the trigger actor, allows a faster identification of the desired workflow run

# Before submitting a PR:

- [x] Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [x] Add JavaDocs and other comments explaining the behavior. 
- [x] When adding or updating methods that fetch entities, add `@link` JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest . 
- [x] Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
- [x] Run `mvn -D enable-ci clean install site` locally. If this command doesn't succeed, your change will not pass CI.
- [x] Push your changes to a branch other than `main`. You will create your PR from that branch.

# When creating a PR: 

- [x] Fill in the "Description" above with clear summary of the changes. This includes:
  - [x] If this PR fixes one or more issues, include "Fixes #<issue number>" lines for each issue. 
  - [x] Provide links to relevant documentation on https://docs.github.com/en/rest where possible. If not including links, explain why not.
- [x] All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
- [x] Enable "Allow edits from maintainers".


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/hub4j/github-api/pull/2006?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 83.26%. Comparing base [(`c8f4815`)](https://app.codecov.io/gh/hub4j/github-api/commit/c8f48156072cc180d5af1df02169ab575627c3fc?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j) to head [(`a64c06b`)](https://app.codecov.io/gh/hub4j/github-api/commit/a64c06b69fe44e0c55ca4aba1d8a6403312569ad?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##               main    #2006   +/-   ##
=========================================
  Coverage     83.26%   83.26%           
- Complexity     2354     2355    +1     
=========================================
  Files           233      233           
  Lines          7229     7230    +1     
  Branches        379      379           
=========================================
+ Hits           6019     6020    +1     
  Misses          973      973           
  Partials        237      237           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/hub4j/github-api/pull/2006?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hub4j).


Patch:
diff --git a/src/main/java/org/kohsuke/github/GHWorkflowRun.java b/src/main/java/org/kohsuke/github/GHWorkflowRun.java
index 6077e4480..4fe887384 100644
--- a/src/main/java/org/kohsuke/github/GHWorkflowRun.java
+++ b/src/main/java/org/kohsuke/github/GHWorkflowRun.java
@@ -42,6 +42,7 @@ public class GHWorkflowRun extends GHObject {
 
     private long runAttempt;
     private String runStartedAt;
+    private GHUser triggeringActor;
 
     private String htmlUrl;
     private String jobsUrl;
@@ -119,6 +120,16 @@ public class GHWorkflowRun extends GHObject {
         return GitHubClient.parseDate(runStartedAt);
     }
 
+    /**
+     * The actor which triggered the run.
+     *
+     * @return the triggering actor
+     */
+    @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
+    public GHUser getTriggeringActor() {
+        return triggeringActor;
+    }
+
     /**
      * Gets the html url.
      *


Test patch:
diff --git a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
index d15f50667..b329857e1 100644
--- a/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
+++ b/src/test/java/org/kohsuke/github/GHWorkflowRunTest.java
@@ -117,6 +117,7 @@ public class GHWorkflowRunTest extends AbstractGitHubWireMockTest {
         assertThat(workflowRun.getStatus(), equalTo(Status.COMPLETED));
         assertThat(workflowRun.getConclusion(), equalTo(Conclusion.SUCCESS));
         assertThat(workflowRun.getHeadSha(), notNullValue());
+        assertThat(workflowRun.getTriggeringActor(), hasProperty("login", equalTo("octocat")));
     }
 
     /**
diff --git a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testManualRunAndBasicInformation/__files/6-r_h_g_actions_runs.json b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testManualRunAndBasicInformation/__files/6-r_h_g_actions_runs.json
index 09bc9af45..00b4c827d 100644
--- a/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testManualRunAndBasicInformation/__files/6-r_h_g_actions_runs.json
+++ b/src/test/resources/org/kohsuke/github/GHWorkflowRunTest/wiremock/testManualRunAndBasicInformation/__files/6-r_h_g_actions_runs.json
@@ -26,6 +26,26 @@
       "cancel_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686034992/cancel",
       "rerun_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/runs/686034992/rerun",
       "workflow_url": "https://api.github.com/repos/hub4j-test-org/GHWorkflowRunTest/actions/workflows/6820790",
+      "triggering_actor": {
+        "login": "octocat",
+        "id": 1,
+        "node_id": "MDQ6VXNlcjE=",
+        "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+        "gravatar_id": "",
+        "url": "https://api.github.com/users/octocat",
+        "html_url": "https://github.com/octocat",
+        "followers_url": "https://api.github.com/users/octocat/followers",
+        "following_url": "https://api.github.com/users/octocat/following{/other_user}",
+        "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
+        "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
+        "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
+        "organizations_url": "https://api.github.com/users/octocat/orgs",
+        "repos_url": "https://api.github.com/users/octocat/repos",
+        "events_url": "https://api.github.com/users/octocat/events{/privacy}",
+        "received_events_url": "https://api.github.com/users/octocat/received_events",
+        "type": "User",
+        "site_admin": false
+      },
       "head_commit": {
         "id": "f6a5c19a67797d64426203b8a7a05a0fd74e5037",
         "tree_id": "666bb9f951306171acb21632eca28a386cb35f73",