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

Implement GHWorkflow, GHWorkflowRun and associated payloads #1064

Merged
merged 7 commits into from
Mar 25, 2021

Conversation

gsmet
Copy link
Contributor

@gsmet gsmet commented Mar 22, 2021

This is a draft for now.

I have several questions and there is at least one big issue with the tests.

@gsmet
Copy link
Contributor Author

gsmet commented Mar 22, 2021

@bitwiseman interested with your wisdom on this one. I added some comments for the big remaining issues from my point of view.

pom.xml Show resolved Hide resolved
@gsmet
Copy link
Contributor Author

gsmet commented Mar 22, 2021

@bitwiseman ok, the situation is a bit better: I was able to get the tests to run in both modes.

So that lets us with the 2 design decisions:

  • enum or not enum for the getStatus/Completion()
  • isolating the API in workflows()

Let me know your take on these two and I'll adjust.

In the meantime, I will work on the payloads.

@bitwiseman
Copy link
Member

bitwiseman commented Mar 22, 2021

  • isolating the API in workflows()

No, it's fine, leave it.

  • enum or not enum for the getStatus/Completion()

I think you could add a bridge method annotation to bring consistency. And we don't need to create class - we can do the same as EnumUtils.getEnum(Class, String, E). We can't update the version of commons-lang due to downstream limitations, but we can use the same behavior.

I would even be fine with not having a getRaw* method. We simply don't support other values. It would make it very clear that any code depending on this method needs to handle the potential case of unknown values.

Final call is yours. Either is acceptable and can be iterated in a future release.

Most of the actions are implemented but not all.
Looks like a good first step.
@gsmet
Copy link
Contributor Author

gsmet commented Mar 23, 2021

I think you could add a bridge method annotation to bring consistency. And we don't need to create class - we can do the same as EnumUtils.getEnum(Class, String, E). We can't update the version of commons-lang due to downstream limitations, but we can use the same behavior.

I implemented a method similar to this except it returns null when the value is null.

I used it for GHWorkflowRun and also added a commit to use it in GHCheckRun (with bridge methods). The enums are different as I'm really not sure they are the same in the underlying API. They have the same values for now but who knows.

I just pushed these changes.

I'm going to work on the payloads next, and also take care of the pull requests potentially attached. In passing, I'll fix a bug in GHCheckRun that my colleague @yrodiere discovered recently while working on something unrelated.

@gsmet gsmet changed the title Workflow runs Implement GHWorkflow, GHWorkflowRun and associated payloads Mar 23, 2021
@gsmet
Copy link
Contributor Author

gsmet commented Mar 24, 2021

@bitwiseman I implemented the payloads in my last commit. From my side, this PR is ready to go. I'll let you review it.

There's still something we need to fix with pull requests for check suites and workflow runs but I'll do it in a separate PR once this is in as it's a preexisting issue and a totally different discussion.

@gsmet gsmet marked this pull request as ready for review March 24, 2021 09:41
@gsmet
Copy link
Contributor Author

gsmet commented Mar 24, 2021

Also, is there a way to test bridge methods?

@bitwiseman
Copy link
Member

bitwiseman commented Mar 24, 2021

Also, is there a way to test bridge methods?

Not really. There is a test to verify they are created, but executing them no. ... I suppose we could add a facility for it using reflection?


public final class EnumUtils {

public static <E extends Enum<E>> E getEnum(Class<E> enumClass, String value, E defaultEnum) {
Copy link
Member

Choose a reason for hiding this comment

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

JavaDoc needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

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

Great work on this! The only remaining feedback I have is on tests. Sorry for the multiple rounds, this is the last one and I'll try to do a better job of batching for future PRs.

workflow.dispatch("main");
workflow.dispatch("main", Collections.singletonMap("parameter", "value"));

// if we implement the logs API at some point, it might be a good idea to validate all this
Copy link
Member

Choose a reason for hiding this comment

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

With wiremock you can verify that specific requests were made. Would that work for validation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have an example in the code base?

Copy link
Member

Choose a reason for hiding this comment

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

I haven't used it in this project.
Here's the docs for it: http://wiremock.org/docs/verifying/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the pointer. Done.

Comment on lines 108 to 121
Awaitility.await().atLeast(atLeast).pollInterval(pollInterval).atMost(atMost).until(() -> {
List<GHWorkflowRun> workflowRuns = getLatestWorkflowRuns(MAIN_BRANCH, Status.IN_PROGRESS);
for (GHWorkflowRun workflowRun : workflowRuns) {
if (workflowRun.getName().equals(SLOW_WORKFLOW_NAME)
&& workflowRun.getId() > latestPreexistingWorkflowRunId) {
assertNotNull(workflowRun.getId());

workflowRun.cancel();
cancelledWorkflowRunId = workflowRun.getId();
return true;
}
}
return false;
});
Copy link
Member

Choose a reason for hiding this comment

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

A few requests applying to all the await sections:

  1. I'd prefer if the until only polled for the state change and the asserts are called after, outside the until.
  2. Let's use getGitHubBeforeAfter() for polling. That way the tests don't need to record the polling. That way when running CI, the test do effectively no waiting.
  3. With (2) we can remove the special polling interval values in setup(). Maybe use a fibonacci polling interval with milliseconds? Recording will burn a few extra requests but they won't be recorded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. yeah that was my inclination as well first and I thought it would be better to reduce the number of API calls. I changed it. I agree it's more readable this way.
  2. ah, yes, good idea, I was looking for a way to do exactly that
  3. I removed the polling when we don't use a proxy. I tried the fibonacci thingy but it doesn't work very well, don't know why but it was just running forever and I don't really have the cycles to dig more into it. Using a fixed poll interval works so I am sticking with that.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, looks great. Bummer about the polling interval, but oh well.

We don't record the polling requests and we avoid any polling when not
recording.
@gsmet
Copy link
Contributor Author

gsmet commented Mar 25, 2021

@bitwiseman I think I addressed all your comments. I would be interested in you releasing a new version once this is in so that I can implement this in my Quarkus GitHub App framework for Jeff!

@bitwiseman bitwiseman merged commit 551dbf2 into hub4j:master Mar 25, 2021
@bitwiseman
Copy link
Member

@gsmet Great work! I'll release today.

@gsmet
Copy link
Contributor Author

gsmet commented Mar 26, 2021

@bitwiseman thanks for the reviews and release! Glad we could get this one in.

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