Skip to content

Conversation

@eugenelesnov
Copy link
Contributor

@eugenelesnov eugenelesnov commented Mar 11, 2021

resolves #123
also relevant to JENKINS-60282

Added environment variables to access NoteEvent (comment on MR) data.

@eugenelesnov eugenelesnov force-pushed the trigger_comment_environment_variable branch from 2683d9a to e618502 Compare March 11, 2021 11:40
Copy link

@boggard boggard left a comment

Choose a reason for hiding this comment

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

Good job, mate!

@MikeSafonov
Copy link

@eugenelesnov Thanks! Your solution lgtm !

@eugenelesnov
Copy link
Contributor Author

@MikeSafonov good 😎

Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I left some comments. Please take a look at it.

* @param commentUrl the URL for the GitLab comment
*/
public GitLabMergeRequestCommentCause(String commentUrl) {
public GitLabMergeRequestCommentCause(String commentUrl, NoteEvent noteEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to add a new constructor instead of changing the existing one. Because you cannot sure there are no others who might need that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, sir

this.variables.put("GITLAB_REPO_VISIBILITY_LEVEL", defaultVisibilityString(noteEvent.getRepository().getVisibility_level()));
this.variables.put("GITLAB_REQUEST_URL", defaultString(noteEvent.getRequestUrl()));
this.variables.put("GITLAB_REQUEST_STRING", defaultString(noteEvent.getRequestQueryString()));
this.variables.put("GITLAB_REQUEST_TOKEN", defaultString(noteEvent.getRequestSecretToken()));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's safe here.

this.variables.put("GITLAB_COMMENT_TRIGGER", defaultString(noteEvent.getObjectAttributes().getNote()));
this.variables.put("GITLAB_USER_ID", defaultIntString(noteEvent.getUser().getId()));
this.variables.put("GITLAB_PROJECT_ID", defaultIntString(noteEvent.getProjectId()));
this.variables.put("GITLAB_PROJECT_ID_2", defaultIntString(noteEvent.getProject().getId()));
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between GITLAB_PROJECT_ID and GITLAB_PROJECT_ID_2?


private final Map<String, String> variables = new HashMap<>();

public GitLabMergeRequestNoteData(NoteEvent noteEvent) {
Copy link
Member

Choose a reason for hiding this comment

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

It's great to have some useful environment variables. But I have two questions about it.

  • How users can know the variable name and its meaning
  • Do we need so many variables? Or they're all?

Copy link
Contributor Author

@eugenelesnov eugenelesnov Jun 28, 2021

Choose a reason for hiding this comment

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

Answering all comments above here. Most of variables were copied from another classes from io.jenkins.plugins.gitlabbranchsource.Cause package. My bad, meh.
For sure, GITLAB_COMMENT_TRIGGER is enough..

@eugenelesnov eugenelesnov force-pushed the trigger_comment_environment_variable branch from e618502 to 579411f Compare June 28, 2021 19:42
@eugenelesnov eugenelesnov force-pushed the trigger_comment_environment_variable branch from 579411f to e2a9688 Compare June 28, 2021 19:57
Copy link
Member

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

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

LGTM

Let's wait for some potential comments from other reviewers.

@LinuxSuRen LinuxSuRen merged commit 29341f7 into jenkinsci:master Jul 15, 2021
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.

Trigger comment environment variable

4 participants