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

Add Jenkins Automation to Accept Command #4

Conversation

gmitch215
Copy link
Member

@gmitch215 gmitch215 commented Jul 10, 2024

Depends on #1 being merged.

This PR uses the jenkins-rest Java API to create a user and the job they were accepted with. The API requests a generated config.xml, for which I have added templates in the resources folders.

The Java Documentation is outdated and lacks JavaDoc comments, so I mostly went off the REST API Documentation. I've tested the various parsing methods, but it should be tested on the CodeMC Beta bot with actual dummy parameters.

Important Note

The GitHub OAuth plugin will hook into whatever username matches their GitHub Profile. The username and project name are based on the URL the reviewer provides (e.g. https://ci.codemc.io/job/gmitch215/job/MobChip).

Other Notes

  • The templates are based on my config.xml and a config.xml from a blank project.
  • There is a new jenkins section in the config.
    • url: The Jenkins URL (https://ci.codemc.io)
    • username: A Jenkins Username to identify the bot
    • token: An API Token with necessary permissions (can also be a GitHub access token from an admin)
  • This adds a freestyle boolean parameter to the accept command that reviewers will need to input depending on the type of project. The description says that "freestyle" is defined as a non-maven project, similar to what the docs specify in making a new project.

String token = config.getString("jenkins", "token");
this.client = JenkinsClient.builder()
.endPoint(url)
.credentials(username + ":" + token)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated question, but should we have a dedicated account for this? I feel like it would be a bit too risky to have one of our accounts used here (Assuming a user-account is used and there isn't a bot-system in Jenkins).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with making a separate bot account. It'll help identify what the bot is doing and could also improve security by only providing necessary permissions (e.g. only create accounts and no delete).

@gmitch215 gmitch215 requested a review from Andre601 July 10, 2024 18:52
Copy link
Collaborator

@Andre601 Andre601 left a comment

Choose a reason for hiding this comment

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

I like this. Hope it will work.

Not the biggest fan of a getLogger method as it can make it more difficult knowing from where the log message came, but that's something that can be changed when necessary.

@gmitch215
Copy link
Member Author

New formats based on @sgdc3's templates. Missed a few errors at the end, but it should be relatively the same.

Also got confirmation that the AuthorizationMatrixProperty in the user config does match their GitHub username/organization name.

gmitch215 added a commit to CodeMC/API that referenced this pull request Jul 23, 2024
@gmitch215 gmitch215 closed this Jul 23, 2024
@gmitch215
Copy link
Member Author

gmitch215 commented Jul 23, 2024

Superceded in a new repository

@Andre601
Copy link
Collaborator

Superceded in a new repository

You used a wrong URL. Corrected it for you :)

@gmitch215 gmitch215 deleted the feat/jenkins-automation branch July 31, 2024 17:54
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.

2 participants