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 Release Bundle Evidence Using Cli Client #14

Merged
merged 9 commits into from
Jul 31, 2024
Merged

Conversation

osaidwtd
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Jul 29, 2024

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
@osaidwtd
❌ @osaidw
osaidw seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@osaidwtd
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@lesnerd lesnerd self-requested a review July 29, 2024 06:06
@lesnerd lesnerd added the feature request New feature or request label Jul 29, 2024
if subject == releaseBundle {
command = NewEvidenceReleaseBundleCommand(c)
}
return command.CreateEvidence(artifactoryClient)

Choose a reason for hiding this comment

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

Unsafe code, the command may be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
platformToEvidenceUrls(artifactoryClient)
return artifactoryClient, nil
if subject == releaseBundle {

Choose a reason for hiding this comment

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

Should be either a switch or if/else (no need to check for if after the match).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -78,16 +62,51 @@ func validateCreateEvidenceContext(c *components.Context) error {
if !c.IsFlagSet(EvdPredicateType) || assertValueProvided(c, EvdPredicateType) != nil {
return errorutils.CheckErrorf("'predicate' is a mandatory field for creating a custom evidence: --%s", EvdPredicateType)

Choose a reason for hiding this comment

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

Typo: predicate-type instead of predicate in the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if !c.IsFlagSet(EvdKey) || assertValueProvided(c, EvdKey) != nil {
return errorutils.CheckErrorf("'key' is a mandatory field for creating a custom evidence: --%s", EvdKey)
}

return nil
}

func getAndValidateSubject(c *components.Context) (string, error) {
subjects := []string{

Choose a reason for hiding this comment

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

Can be moved outside of the function (no need to re-allocate each time).,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if tt.expectErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)

Choose a reason for hiding this comment

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

The NoError is not reachable (all cases are negative, please add one with expectErr: false)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
)

type EvidenceCustomCommand struct {

Choose a reason for hiding this comment

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

Why is it an exported struct and not an interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
)

type EvidenceReleaseBundleCommand struct {

Choose a reason for hiding this comment

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

Why is it an exported struct and not an interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockExec := func(command commands.Command) error {

Choose a reason for hiding this comment

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

The override can be applied once for all the test cases:

	execFunc = func(command commands.Command) error {
		return nil
	}

(no need to repeat the same mockExec and defer the restoration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

rtDetails.ArtifactoryUrl = utils.AddTrailingSlashIfNeeded(rtDetails.Url) + "artifactory/"
rtDetails.EvidenceUrl = utils.AddTrailingSlashIfNeeded(rtDetails.Url) + "evidence/"
}
var execFunc = exec

Choose a reason for hiding this comment

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

As the exec function is used only from this variable, it can be inlined like:

var execFunc = func(command commands.Command) error {
	return commands.Exec(command)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

var subjectTypes = []string{
EvdRepoPath,

Choose a reason for hiding this comment

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

The EvdRepoPath can be non-exported (the same as releaseBundle).
Also, the type name is quite confusing, is it subjectRepoPath or just repoPath?
(we do not specify a path to the evidence itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Choose a reason for hiding this comment

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

Please, do not commit mocks.
Need to add *_mock.go to the .gitignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

log.Warn(fmt.Sprintf("failed to read predicate file '%s'", predicate))
return nil, err
}
//client.NewClient(c.serverDetails)

Choose a reason for hiding this comment

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

Please, remove the commented-out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@osaidwtd osaidwtd merged commit 80b89c1 into jfrog:main Jul 31, 2024
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants