-
Notifications
You must be signed in to change notification settings - Fork 173
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
feat(warehouse): allow discovery interval and limit configurations #2038
Changes from all commits
377a33a
1a70e1f
ec0d712
7c24443
c978f5f
b72345d
83af0f3
4c8cc05
7548a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,9 +90,13 @@ func (r *reconciler) discoverCommits( | |
|
||
for _, meta := range tags { | ||
discovered = append(discovered, kargoapi.DiscoveredCommit{ | ||
ID: meta.CommitID, | ||
Tag: meta.Tag, | ||
Subject: meta.Subject, | ||
ID: meta.CommitID, | ||
Tag: meta.Tag, | ||
// A decent subject length for a commit message is 50 characters | ||
// (based on the 50/72 rule). We are nice people, and allow a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
😂 ❤️ |
||
// bit more. But not an excessive amount, to minimize the risk of | ||
// exceeding the maximum size of the object in the API server. | ||
Subject: shortenString(meta.Subject, 80), | ||
Author: meta.Author, | ||
Committer: meta.Committer, | ||
CreatorDate: &metav1.Time{Time: meta.CreatorDate}, | ||
|
@@ -106,9 +110,13 @@ func (r *reconciler) discoverCommits( | |
|
||
for _, meta := range commits { | ||
discovered = append(discovered, kargoapi.DiscoveredCommit{ | ||
ID: meta.ID, | ||
Branch: sub.Branch, | ||
Subject: meta.Subject, | ||
ID: meta.ID, | ||
Branch: sub.Branch, | ||
// A decent subject length for a commit message is 50 characters | ||
// (based on the 50/72 rule). We are nice people, and allow a | ||
// bit more. But not an excessive amount, to minimize the risk of | ||
// exceeding the maximum size of the object in the API server. | ||
Subject: shortenString(meta.Subject, 80), | ||
Author: meta.Author, | ||
Committer: meta.Committer, | ||
CreatorDate: &metav1.Time{Time: meta.CommitDate}, | ||
|
@@ -126,10 +134,10 @@ func (r *reconciler) discoverCommits( | |
} | ||
|
||
func (r *reconciler) discoverBranchHistory(repo git.Repo, sub kargoapi.GitSubscription) ([]git.CommitMetadata, error) { | ||
const limit = 20 | ||
limit := int(sub.DiscoveryLimit) | ||
var filteredCommits = make([]git.CommitMetadata, 0, limit) | ||
for skip := uint(0); ; skip += limit { | ||
commits, err := r.listCommitsFn(repo, limit, skip) | ||
for skip := uint(0); ; skip += uint(limit) { | ||
commits, err := r.listCommitsFn(repo, uint(limit), skip) | ||
if err != nil { | ||
return nil, fmt.Errorf("error listing commits from git repo %q: %w", sub.RepoURL, err) | ||
} | ||
|
@@ -223,7 +231,7 @@ func (r *reconciler) discoverTags(repo git.Repo, sub kargoapi.GitSubscription) ( | |
|
||
// If no include or exclude paths are specified, return the first tags up to | ||
// the limit. | ||
const limit = 20 | ||
limit := int(sub.DiscoveryLimit) | ||
if len(tags) == 0 || (sub.IncludePaths == nil && sub.ExcludePaths == nil) { | ||
return trimSlice(tags, limit), nil | ||
} | ||
|
@@ -441,3 +449,12 @@ func (r *reconciler) listTags(repo git.Repo) ([]git.TagMetadata, error) { | |
func (r *reconciler) getDiffPathsForCommitID(repo git.Repo, commitID string) ([]string, error) { | ||
return repo.GetDiffPathsForCommitID(commitID) | ||
} | ||
|
||
// shortenString truncates the given string to the given length, appending an | ||
// ellipsis if the string is longer than the length. | ||
func shortenString(str string, length int) string { | ||
if length >= 0 && len(str) > length { | ||
return str[:length] + "..." | ||
} | ||
return str | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a common workaround for the issue described here: kubernetes/apiextensions-apiserver#56
I took the further liberty to drop
ms
from the regex, as we probably do not want people to go below the seconds (and the level of precision in combination with e.g. minutes has little value).