Add support for artifacts and logs of workflow runs by gsmet · Pull Request #1075 · hub4j/github-api · GitHub
Skip to content

Add support for artifacts and logs of workflow runs#1075

Merged
bitwiseman merged 1 commit into
hub4j:masterfrom
gsmet:more-workflows
Apr 2, 2021
Merged

Add support for artifacts and logs of workflow runs#1075
bitwiseman merged 1 commit into
hub4j:masterfrom
gsmet:more-workflows

Conversation

@gsmet

@gsmet gsmet commented Apr 1, 2021

Copy link
Copy Markdown
Contributor

@bitwiseman I need your wisdom. The logs and artifacts are downloaded from another host (https://pipelines.actions.githubusercontent.com/) and the way it's done currently, this call is not mocked properly.

See https://github.com/hub4j/github-api/pull/1075/files#diff-87252b4de52f4e0e1317a91eee8a0de1cc885f7b84f872989c8e52ec09d2509dR296 for an example of how it is currently done.

I'm unsure of how we could handle this and thought I might as well ask.

Note: the PR is not completed yet, it's still missing tests for the artifacts. I only test the logs method for now.

mvn install -Dtest.github.takeSnapshot -Dtest=GHWorkflowRunTest#testLogs

works but running the test after that doesn't work as the actual download call wasn't mocked.

@gsmet

gsmet commented Apr 1, 2021

Copy link
Copy Markdown
Contributor Author

@bitwiseman

Copy link
Copy Markdown
Member

@gsmet
You'll need to add another server mapping to the GitHubWireMockRule. 472034c#diff-1087a33f8255b3b68f161247f32cb0f53a4457b8b92b4af5305c5f264c543a35 added codeload. Repeat that for your new server.

Comment thread src/main/java/org/kohsuke/github/GHWorkflowRun.java Outdated
Comment on lines +2977 to +2982
try {
GitHubRequest request = root.createRequest().withUrlPath(getApiTailUrl("actions/artifacts")).build();
return new GHArtifactsIterable(this, request);
} catch (MalformedURLException e) {
throw new GHException("Malformed URL", e);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's that try-catch again. I figured out why most other list* methods don't need this:

public <R> PagedIterable<R> toIterable(Class<R[]> type, Consumer<R> itemInitializer) {
try {
return new GitHubPageContentsIterable<>(client, build(), type, itemInitializer);
} catch (MalformedURLException e) {
throw new GHException(e.getMessage(), e);
}

This try catch appears in two places so in this case I definitely want it inside the iterable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I knew you would say that but the query is different in both cases, thus why I haven't changed it as for the other PR. So should I pass the builder instead of the request and build the request in the iterable?

Frankly, for me the issue is with the initial design decision of throwing low value unchecked exceptions from nearly everywhere.

@bitwiseman bitwiseman Apr 2, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I knew you would say that but the query is different in both cases, thus why I haven't changed it as for the other PR. So should I pass the builder instead of the request and build the request in the iterable?

Yeah, pass the builder. Or maybe the right thing is to make a version of the build() that wraps those exceptions and use that in all 3 (4?) calls. I would change the behavior of build() but that could result in client that understand how to handle certain exceptions suddenly not getting those anymore.

Frankly, for me the issue is with the initial design decision of throwing low value unchecked exceptions from nearly everywhere.

Absolutely. Please file an issue and describe how it should work in the next version, or any improvements we can safely make now. I'm interested. Some of the current behavior is probably cruft from long removed code. It may also be a result of the underlying implementation of HttpConnector and HttpUrlConnection not being controlled by this library. okhttp3 has notably different behavior from the Java built-in implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, for now, I passed the builder to the iterable.

I think more involved changes need to be thought out a bit more. I'll think about it and open an issue.

Comment thread src/main/java/org/kohsuke/github/GHWorkflowRunsIterable.java Outdated

@jeffmaury jeffmaury left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should cover my needs

Comment thread src/main/java/org/kohsuke/github/GHWorkflowRun.java Outdated
@gsmet

gsmet commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

OK, things look significantly better now. The logs tests are passing. I need to add tests for the artifacts now. I'll probably do that this evening.

@bitwiseman I'll wait for your feedback on the MalformedURLException question and I'll fix it accordingly.

@gsmet gsmet force-pushed the more-workflows branch 3 times, most recently from 66d4d3f to 50b5396 Compare April 2, 2021 16:58
@gsmet gsmet marked this pull request as ready for review April 2, 2021 16:58
@gsmet

gsmet commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

@bitwiseman this is now complete - I implemented all the features I wanted and the test coverage should be OK. Let me know what you want me to do for the MalformedURLException and I'll adjust the PR.

Feel free to ask other adjustments too :).

@gsmet

gsmet commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

All green!

@bitwiseman bitwiseman merged commit 78ffe5a into hub4j:master Apr 2, 2021
@gsmet

gsmet commented Apr 2, 2021

Copy link
Copy Markdown
Contributor Author

Thanks! As usual, interested by a release when you get the time. We want to put this to good use :).

@bitwiseman

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants