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

No comment if multiple sources are given #1021

Closed
int128 opened this issue Jan 3, 2024 · 0 comments · Fixed by #1022
Closed

No comment if multiple sources are given #1021

int128 opened this issue Jan 3, 2024 · 0 comments · Fixed by #1022
Labels
bug Something isn't working

Comments

@int128
Copy link
Owner

int128 commented Jan 3, 2024

After #955, the controller does not create a comment to a pull request if multiple sources are given. For example, int128/argocd-commenter-e2e-test#2531.

It needs to consider Sources here:

func isPullRequestRelatedToEvent(pull github.PullRequest, app argocdv1alpha1.Application) bool {
if app.Spec.Source == nil {
return false
}
// support manifest path annotation
// see https://argo-cd.readthedocs.io/en/stable/operator-manual/high_availability/#webhook-and-manifest-paths-annotation
// https://github.com/int128/argocd-commenter/pull/656
manifestGeneratePaths := getManifestGeneratePaths(app)
for _, file := range pull.Files {
if strings.HasPrefix(file, app.Spec.Source.Path) {
return true
}
for _, path := range manifestGeneratePaths {
if strings.HasPrefix(file, path) {
return true
}
}
}
return false
}
// getManifestGeneratePaths returns canonical paths of "argocd.argoproj.io/manifest-generate-paths" annotation.
// It returns nil if the field is nil or empty.
// https://argo-cd.readthedocs.io/en/stable/operator-manual/high_availability/#webhook-and-manifest-paths-annotation
func getManifestGeneratePaths(app argocdv1alpha1.Application) []string {
if app.Annotations == nil {
return nil
}
if app.Spec.Source == nil {
return nil
}
var canonicalPaths []string
annotatedPaths := strings.Split(app.Annotations["argocd.argoproj.io/manifest-generate-paths"], ";")
for _, path := range annotatedPaths {
if path == "" {
return nil
}
// convert to absolute path
absolutePath := path
if !filepath.IsAbs(path) {
absolutePath = filepath.Join(app.Spec.Source.Path, path)
}
// remove leading slash
if absolutePath[0:1] == "/" {
absolutePath = absolutePath[1:]
}
// add to list of manifest paths
canonicalPaths = append(canonicalPaths, absolutePath)
}
return canonicalPaths
}

@int128 int128 added the bug Something isn't working label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant