-
Notifications
You must be signed in to change notification settings - Fork 53
SUP-2141 Add build resolver structure #235
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
049b47c
Move build version number to version package
48b33a1
Restructure internal/build
478a63c
Add build resolver aggregate similar to pipelines
6d9e9fc
Add context to other resolvers
d6ac645
Update tests to add context
bf3c1f6
Update build url resolver
1a22d89
Remove build resolver memoization
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| package build | ||
|
|
||
| // Version is dynamically set at build time through ldflags | ||
| var Version = "DEV" | ||
| type Build struct { | ||
| Organization string | ||
| Pipeline string | ||
| BuildNumber string | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package resolver | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/buildkite/cli/v3/internal/build" | ||
| ) | ||
|
|
||
| // BuildResolverFn is a function for finding a build. It returns an error if an irrecoverable scenario happens and | ||
| // should halt execution. Otherwise, if the resolver does not find a build, it should return (nil, nil) to indicate | ||
| // this. ie. no error occurred, but no build was found either | ||
| type BuildResolverFn func(context.Context) (*build.Build, error) | ||
|
|
||
| type AggregateResolver []BuildResolverFn | ||
|
|
||
| // Resolve is a BuildResolverFn that wraps up a list of resolvers to loop through and try find a build. The first build | ||
| // to be found will be returned. If none are found, it won't return an error to match the expectation of a | ||
| // BuildResolverFn | ||
| // | ||
| // This is safe to call multiple times, the same result will be returned | ||
| func (ar AggregateResolver) Resolve(ctx context.Context) (*build.Build, error) { | ||
| for _, resolve := range ar { | ||
| b, err := resolve(ctx) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if b != nil { | ||
| return b, nil | ||
| } | ||
| } | ||
|
|
||
| return nil, nil | ||
| } | ||
|
|
||
| // NewAggregateResolver creates an AggregateResolver from a list of BuildResolverFn, appending a final resolver for | ||
| // capturing the case that no build is found by any resolver | ||
| func NewAggregateResolver(resolvers ...BuildResolverFn) AggregateResolver { | ||
| return append(resolvers, errorResolver) | ||
| } | ||
|
|
||
| func errorResolver(context.Context) (*build.Build, error) { | ||
| return nil, errors.New("Failed to find a build.") | ||
| } |
7 changes: 4 additions & 3 deletions
7
internal/build/resolvers/resolvefromurl.go → internal/build/resolver/url.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package version | ||
|
|
||
| // Version is dynamically set at build time through ldflags | ||
| var Version = "DEV" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Eg, if this resolver needed to know the pipeline to be able to resolve the build (ie thinking "most recent build on a branch for a pipeline"), we would bind in a PipelineResolverFn here for the function to use. The signature of the build resolver would remain the same and we don't need to expose that dependency to other resolvers that may not need it (like this one)
Uh oh!
There was an error while loading. Please reload this page.
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.
The API request that is made to determine the "most recent build" would also make use of the context passed in so that it could cancel the request