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 possibility to collect metrics from branch or pullRequest analysis #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lukzeg
Copy link
Contributor

@lukzeg lukzeg commented Apr 27, 2022

Hi @adisreyaj , @pedroresende

I would like to propose small extension to your plugin. I would like to extend it via adding possibility to collect metrics from pullRequest or branch analysis.

For instance if the end user would like to receive analysis from pullRequest, he might define new attribute pullRequest:
{ "project": "adisreyaj_compito", "sonarURL": "https://sonarcloud.io", "pullRequest": 212, "auth": { "username": "", "password": "" } }
or branch:
{ "project": "adisreyaj_compito", "sonarURL": "https://sonarcloud.io", "branch": "bugfix/FixMe", "auth": { "username": "", "password": "" } }

In case if both of attrs are added, the highest priority will have pullRequest, as mostly engineers will be interested to see potential issues which they deliver to master branch.

Please let me know if this feature looks okay for you.

Kind Regards,
Lucas

export function isPullRequestOrBranchConfigured(config: Config) {
let returnVal = {};

let isBranchConfigured = has(config, 'branch') && !config.branch.includes('optional-branch-name');
Copy link
Contributor

Choose a reason for hiding this comment

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

replace let by const please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

let returnVal = {};

let isBranchConfigured = has(config, 'branch') && !config.branch.includes('optional-branch-name');
let isPullRequestConfigured = has(config, 'pullRequest') && !config.pullRequest.includes('optional-pull-request-id');
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.


if ( isBranchConfigured || isPullRequestConfigured) {
if ( isBranchConfigured ) {
returnVal = { branch: config.branch };
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My apologies. I'm working in another project in C and we use only one return at the end of function. Updated

Copy link
Contributor

Choose a reason for hiding this comment

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

you don't have to apologise, you did a great job, my remarks are only improvements nothing else 🎉


// Give pullRequest highest priority
if ( isPullRequestConfigured ) {
returnVal = { pullRequest: config.pullRequest };
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return directly?

}

export function isPullRequestOrBranchConfigured(config: Config) {
let returnVal = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

not needed

returnVal = { pullRequest: config.pullRequest };
}
}
return (
Copy link
Contributor

Choose a reason for hiding this comment

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

not 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.

Removed.

returnVal = { branch: config.branch };
}

// Give pullRequest highest priority
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want to give highest priority you can move before the if ( isBranchConfigured ) { and return directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @pedroresende ,
I refactored changes. Thanks for the tip.

@lukzeg lukzeg force-pushed the feature/branch_and_pullRequest_analysis branch from 2e5eace to 6ac46c8 Compare April 27, 2022 09:31
if ( isPullRequestConfigured ) {
return { pullRequest: config.pullRequest };
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

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

nbd: you don't need the else

@lukzeg lukzeg force-pushed the feature/branch_and_pullRequest_analysis branch from 6ac46c8 to 396ae96 Compare April 27, 2022 19:03
@adisreyaj
Copy link
Owner

adisreyaj commented Apr 30, 2022

@lukzeg It's really a good enhancement to have. Here are my thoughts on the approach.

I personally feel that this should be easier for the user, i.e by a dropdown or something instead of having to update the config file every time.

The config file should be considered as a one-time setup process.

What do y'all think?

@lukzeg @pedroresende

@lukzeg lukzeg force-pushed the feature/branch_and_pullRequest_analysis branch from 396ae96 to ba74af1 Compare May 1, 2022 20:02
@lukzeg
Copy link
Contributor Author

lukzeg commented May 1, 2022

Hi @adisreyaj , @pedroresende ,

The idea to create settings part sound really great. I think it will be great to create some milestone with such of feature. So anyone who is interested might start to work on it.

I would like to avoid of making such of change in current PRst, just to simplify the commits and parts which are delivered. I know that might be a strange, but small parts of code are much more easier to be Code Reviewed.

What do you think about creating some milestones, with ideas of future improvements required/ request by you and other users?

@lukzeg lukzeg force-pushed the feature/branch_and_pullRequest_analysis branch 3 times, most recently from a143e92 to 286709c Compare May 2, 2022 19:45
lukzeg added 2 commits May 4, 2022 12:32
Update README.md with information about optional arguments:
- branch
- pullRequest
Add errorMsg when pullRequest or branch is not longer available at SonarQube server
@lukzeg lukzeg force-pushed the feature/branch_and_pullRequest_analysis branch from 286709c to d56e487 Compare May 4, 2022 10:33
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