-
Notifications
You must be signed in to change notification settings - Fork 505
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
gcbmgr: add list build jobs #1194
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,8 +27,12 @@ import ( | |
"sync" | ||
|
||
"github.com/google/uuid" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"golang.org/x/net/context" | ||
"google.golang.org/api/cloudbuild/v1" | ||
"google.golang.org/api/option" | ||
|
||
"k8s.io/release/pkg/command" | ||
"k8s.io/release/pkg/git" | ||
|
@@ -348,3 +352,28 @@ func mergeMaps(maps ...map[string]string) map[string]string { | |
} | ||
return out | ||
} | ||
|
||
func ListJobs(project string, lastJobs int64) error { | ||
ctx := context.Background() | ||
opts := option.WithCredentialsFile("") | ||
|
||
service, err := cloudbuild.NewService(ctx, opts) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to fetching gcloud credentials... try running \"gcloud auth application-default login\"") | ||
} | ||
|
||
req, err := service.Projects.Builds.List(project).PageSize(lastJobs).Do() | ||
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. Is there a maximum value for the page size? If yes, what do we do if we’re requesting more jobs? 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. i tried to find in the docs but it does not say anything 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. Fair, do page sizes > 100 work? 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. i did with 301 and returned all 301 last jobs 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. Sounds good to me, thanks for verifying. 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. tried with 500 :) 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. i think this is not useful but a user can do weird things 😂 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. What happens on 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. it brings the jobs in the future :P but looks like it not fail
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. Follow-up: Normalize (set to default count) any non-positive number. Also, log that we're going to do that |
||
if err != nil { | ||
return errors.Wrap(err, "failed to listing the builds") | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetHeader([]string{"Start Time", "Finish Time", "Status", "Console Logs"}) | ||
|
||
for _, build := range req.Builds { | ||
table.Append([]string{strings.TrimSpace(build.StartTime), strings.TrimSpace(build.FinishTime), strings.TrimSpace(build.Status), strings.TrimSpace(build.LogUrl)}) | ||
} | ||
table.Render() | ||
|
||
return nil | ||
} |
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.
As a follow up I suggest to wrap this in a new struct like we do in the
guthub
package. :)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.
ok, I will review the github package and apply the same in a follow up.
thanks!