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

Support state reason for issues #1793

Merged
merged 3 commits into from
Feb 20, 2024
Merged

Support state reason for issues #1793

merged 3 commits into from
Feb 20, 2024

Conversation

stianst
Copy link
Contributor

@stianst stianst commented Feb 14, 2024

Hi, first of thanks for providing this library. I'm using it quite a lot, but finding a few things that are missing for my needs, and trying to contribute those, with the first one being supporting closing issues as not planned.

Trying to figure out how to work with the testsuite, but having a few issues.

When running mvn install -Dtest.github.org=false -Dtest=GHIssueTest I'm getting the following exception:

Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.String java.net.HttpURLConnection.method accessible: module java.base does not "opens java.net" to unnamed module @551bca18

Another thing is the test is hardwired to hub4j-test-org which I don't have access to, so guess I need to use my own repository somehow.

Closes #1792

@gsmet
Copy link
Contributor

gsmet commented Feb 14, 2024

Hey @stianst ,

Yeah, you usually need access to the test org when recording testing as it's easier for them to be reproduced by others when something needs a change.

You need @bitwiseman for that.

As for the error you have when running the tests, the test runs by default with an HTTP Client that is not compatible with Java 17+. Run them with Java 11 and things should work better.

@gsmet
Copy link
Contributor

gsmet commented Feb 14, 2024

Ah, actually, good news, I forgot I had the permission to do that.

I added you to the test org. You should have received an invite.

@bitwiseman Stian is a colleague from Red Hat leading the Keycloak project.

Copy link
Contributor

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I spotted a few minor issues.

@@ -67,6 +69,9 @@ public class GHIssue extends GHObject implements Reactable {
/** The state. */
protected String state;

/** The state. */
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs an update

* @return the state reason
*/
public GHIssueStateReason getStateReason() {
return Enum.valueOf(GHIssueStateReason.class, state_reason.toUpperCase(Locale.ENGLISH));
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you were trying to be consistent with the one above but we have a new way of doing this:

  • add an UNKNOWN value to your enum
  • use EnumUtils.getEnumOrDefault() (there are plenty of examples in the source code). There is also a method supporting null value, you probably need to check if the state_reason can be null... which is probably the case. In this case, you would need to use getNullableEnumOrDefault.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, that's much better. Updated to use that.

/*
* The MIT License
*
* Copyright (c) 2011, Eric Maupin
Copy link
Contributor

Choose a reason for hiding this comment

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

This is off. But I'm not sure if we are encouraged to put our name here, these days. @bitwiseman would know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked at a couple recent commits and they don't have any license headers so removed this.


public enum GHIssueStateReason {

COMPLETED, NOT_PLANNED
Copy link
Contributor

Choose a reason for hiding this comment

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

As previously stated, you can add UNKNOWN here. This avoids errors when GitHub add a new value.

@gsmet
Copy link
Contributor

gsmet commented Feb 14, 2024

Ah also, do not record things for all the tests, doing:

rm -rf src/test/resources/org/kohsuke/github/GHIssueTest/wiremock/closeIssue/
mvn install -Dtest.github.takeSnapshot -Dtest=GHIssueTest#closeIssue
rm -rf src/test/resources/org/kohsuke/github/GHIssueTest/wiremock/closeIssueNotPlanned/
mvn install -Dtest.github.takeSnapshot -Dtest=GHIssueTest#closeIssueNotPlanned

will be better.

Then you should add the new snapshots to your commit.

@stianst stianst force-pushed the state_reason branch 2 times, most recently from a6ed0f6 to 0c41dd7 Compare February 14, 2024 09:37
@stianst
Copy link
Contributor Author

stianst commented Feb 14, 2024

Got the test working eventually (well, okay I only spent 30 min, so this wasn't too bad ;)), but used an org I created for the purpose. Will try with the official org and update the data.

@stianst
Copy link
Contributor Author

stianst commented Feb 14, 2024

@gsmet @bitwiseman would it be okay to enable fine-grained personal access tokens for the org (https://github.com/organizations/hub4j-test-org/settings/personal-access-tokens-onboarding). They are a bit nicer than the legacy tokens as you can limit to a specific org/repo.

@stianst stianst marked this pull request as ready for review February 14, 2024 10:23
@stianst stianst force-pushed the state_reason branch 2 times, most recently from d911b1e to 5b3e6d0 Compare February 14, 2024 10:24
@stianst stianst requested a review from gsmet February 14, 2024 10:25
@stianst
Copy link
Contributor Author

stianst commented Feb 14, 2024

Should be ready to go now

Copy link
Contributor

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

I added a very small comment for something that we need to check but otherwise it looks very good.

Note that we will have to wait for @bitwiseman to merge it as I'm not a committer here.

* @return the state reason
*/
public GHIssueStateReason getStateReason() {
return EnumUtils.getEnumOrDefault(GHIssueStateReason.class, state_reason, GHIssueStateReason.UNKNOWN);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this can't be null? My understanding is that when the issue is not closed, it will be null but I might be mistaken.
If so, please use EnumUtils.getNullableEnumOrDefault(). I pointed you to it in my previous comment but it might have been a bit confusing as I pointed to this one first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, I was kinda thinking it should be set to UNKNOWN when null, but obviously null makes more sense ;)

@bitwiseman
Copy link
Member

@gsmet @bitwiseman would it be okay to enable fine-grained personal access tokens for the org (https://github.com/organizations/hub4j-test-org/settings/personal-access-tokens-onboarding). They are a bit nicer than the legacy tokens as you can limit to a specific org/repo.

Enabled the fine-grained PATs.

Copy link

codecov bot commented Feb 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (be00e51) 80.64% compared to head (ddaec5f) 80.69%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1793      +/-   ##
============================================
+ Coverage     80.64%   80.69%   +0.04%     
- Complexity     2322     2328       +6     
============================================
  Files           219      220       +1     
  Lines          7027     7043      +16     
  Branches        371      371              
============================================
+ Hits           5667     5683      +16     
  Misses         1128     1128              
  Partials        232      232              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stianst
Copy link
Contributor Author

stianst commented Feb 16, 2024

Fixed the last issue with using EnumUtils.getNullableEnumOrDefault and added Javadocs to GHIssueStateReason since the site job complained about that.

@stianst
Copy link
Contributor Author

stianst commented Feb 20, 2024

@bitwiseman hi, sorry to ping you on this as I'm sure you're busy with other stuff. Just wondering a bit on when/if this could be merged and what the plans are for a new release? I'm a bit blocked on this for some automation for the Keycloak project.

@bitwiseman bitwiseman merged commit 5c155dc into hub4j:main Feb 20, 2024
11 checks passed
@stianst stianst deleted the state_reason branch February 22, 2024 13:04
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.

State reason for issues not supported
3 participants