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

Show the "GitHub" link for Workflow projects #105

Merged

Conversation

arthurschreiber
Copy link
Contributor

This will make the "GitHub" Link show up on Workflow Jobs and other similar types (like Multibranch Workflow Jobs).

Review on Reviewable

@Override
public Collection<? extends Action> createFor(Job j) {
GithubProjectProperty prop =
(GithubProjectProperty) ((Job<?, ?>) j).getProperty(GithubProjectProperty.class);
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that you need cast it? Why job is also recasted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember my IDE complaining here for both of these.

Copy link
Member

Choose a reason for hiding this comment

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

If you cast to Job<?,?> you should get a well-typed return value from getProperty. Or you can use (GithubProjectProperty) j.getProperty(GithubProjectProperty.class).

@jenkinsadmin
Copy link
Member

Thank you for this pull request! Please check this document for how the Jenkins project handles pull requests.

}

@Override
public Collection<? extends Action> createFor(Job j) {
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried (Job<?, ?> j) here and remove casts?

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't work, as it should have same signature as in generic

Copy link
Member

Choose a reason for hiding this comment

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

Right, due to Java erasure it is not possible to do better, except perhaps with more exotic type tokens.

@lanwen
Copy link
Member

lanwen commented Jan 13, 2016

Please also add simple unit test which will call createFor on project with/without property

@arthurschreiber
Copy link
Contributor Author

@lanwen I fixed the code issues and will add unit tests asap.

@arthurschreiber
Copy link
Contributor Author

Hey @lanwen @jglick @KostyaSha

I just updated this PR to include test cases. Please keep the feedback coming, I usually don't do Java development, so my knowledge of "Java best-practices" is spotty at best and I'm happy for any suggestions that you might have.

@arthurschreiber
Copy link
Contributor Author

@lanwen Do I need to resolve the comments pointed out by @dummy-lanwen-bot ?

I don't feel that adding custom error messages to these assertions is going to help a lot, but if that's something that is important, I can fix this up.

@KostyaSha
Copy link
Member

@arthurschreiber yes, describe something. After 1 year it will be very difficult understand what happened in test when you get this error from some integration system.

assertThat(actions.size(), is(equalTo(1)));

GithubLinkAction action = (GithubLinkAction) actions.iterator().next();
assertThat(action.getUrlName(), is(equalTo("https://github.com/jenkinsci/github-plugin/")));
Copy link
Member

Choose a reason for hiding this comment

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

please add here comment "url name".
Also is(equalTo()) is the same as simple is()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added some descriptions for all assertions.

@arthurschreiber arthurschreiber force-pushed the arthur/extend-workflow-support branch 2 times, most recently from d6a2a70 to f6815e2 Compare January 14, 2016 10:20
@arthurschreiber
Copy link
Contributor Author

@KostyaSha I'm not new to unit testing, but I often feel there's cases where adding a custom description ends up as being nothing more than boilerplate that no one ever needs.

As long as the checks that are done inside the test cases (1 assertion per test), the test names should be enough description. And if your tests end up using many assertions, a custom matcher with a custom error formatting might be more appropriate.

Anyway, I performed all the suggested changes, feel free to review again.

@Test
public void shouldCreateGithubLinkActionForJobWithGithubProjectProperty() throws IOException {
WorkflowJob job = createExampleJob();
String url = "https://github.com/jenkinsci/github-plugin/";
Copy link
Member

Choose a reason for hiding this comment

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

please move it to const
private static final String GH_PROJECT = "..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry to ask, but what would be the benefit of that? This value is not used in any other test case, so making it a property on the class does not make me feel like it has any obvious benefits.

Again, I'm no Java Expert, so if there's benefits to this, feel free to let me know. Learning new things is always good. 😄

Copy link
Member

Choose a reason for hiding this comment

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

its not the test value itself, its just a some data which should remain the same in this test.
Vars should be used if they make some active role in the test
http://xunitpatterns.com/, page 192 (Irrelevant information)

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 explanation! ❤️

@arthurschreiber arthurschreiber force-pushed the arthur/extend-workflow-support branch 2 times, most recently from 3fc843e to c6cdaa0 Compare January 14, 2016 10:59
@lanwen
Copy link
Member

lanwen commented Jan 14, 2016

@arthurschreiber u're right for 1 assertion for one test and custom matchers ❤️
your test names is very good, so the assertion comment can be omitted in cases where the matcher + test title says the cause of error. In case of more than one assertion in case, comment should help to define context of error. So it can explain the cause of this check, or simply point the place and the subject of checks.

I've commented the examples of such comments

@arthurschreiber
Copy link
Contributor Author

I'll perform your suggested changes (you are maintaining the project, overall). ❤️

So it can explain the cause of this check, or simply point the place and the subject of checks

Yeah, I feel that using plain assert method itself without any description is a big NO-NO. For specific matchers (like instanceOf), I usually feel that adding a custom description does usually not provide much, the matcher already has very specific error messages, and the stack trace provides line numbers anyway.

Did I miss anything?

@lanwen
Copy link
Member

lanwen commented Jan 14, 2016

only const for url now. Add it, and i'll merge and release

…Actions`.

This makes the "GitHub" link also show up for Workflow projects.
@arthurschreiber
Copy link
Contributor Author

@lanwen Can you check again? 👍

return rule.getInstance().createProject(WorkflowJob.class, "example");
}

private GithubProjectProperty createExampleProperty() {
Copy link
Member

Choose a reason for hiding this comment

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

could be inlined, but nvm

lanwen added a commit that referenced this pull request Jan 14, 2016
…upport

Show the "GitHub" link for Workflow projects
@lanwen lanwen merged commit ad03690 into jenkinsci:master Jan 14, 2016
@arthurschreiber
Copy link
Contributor Author

Thank you so much for putting up with my lack of Java knowledge. And thanks for merging this and releasing it so quickly. 😄

@arthurschreiber arthurschreiber deleted the arthur/extend-workflow-support branch January 15, 2016 08:58
@lanwen
Copy link
Member

lanwen commented Jan 15, 2016

thanks for PR and quick review fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants