-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add export functionality to codespace commands #4591
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
Changes from all commits
badbf51
cbeb675
a5fa70a
905cb3b
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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ import ( | |
| "io/ioutil" | ||
| "net/http" | ||
| "net/url" | ||
| "reflect" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
|
|
@@ -176,6 +177,44 @@ type CodespaceConnection struct { | |
| HostPublicKeys []string `json:"hostPublicKeys"` | ||
| } | ||
|
|
||
| // CodespaceFields is the list of exportable fields for a codespace. | ||
| var CodespaceFields = []string{ | ||
| "name", | ||
| "owner", | ||
| "repository", | ||
| "state", | ||
| "gitStatus", | ||
| "createdAt", | ||
| "lastUsedAt", | ||
| } | ||
|
|
||
| func (c *Codespace) ExportData(fields []string) *map[string]interface{} { | ||
|
Contributor
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. A Go map value is a reference to a hash table, so you almost never need *map types.
Contributor
Author
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. Ah good to know! I will address this across all commands in a followup PR. |
||
| v := reflect.ValueOf(c).Elem() | ||
| data := map[string]interface{}{} | ||
|
|
||
| for _, f := range fields { | ||
| switch f { | ||
| case "owner": | ||
| data[f] = c.Owner.Login | ||
| case "repository": | ||
| data[f] = c.Repository.FullName | ||
| case "gitStatus": | ||
| data[f] = map[string]interface{}{ | ||
| "ref": c.GitStatus.Ref, | ||
| "hasUnpushedChanges": c.GitStatus.HasUnpushedChanges, | ||
| "hasUncommitedChanges": c.GitStatus.HasUncommitedChanges, | ||
| } | ||
| default: | ||
| sf := v.FieldByNameFunc(func(s string) bool { | ||
|
Contributor
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 when f is misspelled? I suspect the map has an (f, nil) entry. It would be better to log.Fatal.
This comment was marked as spam.
Sorry, something went wrong.
Contributor
Author
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 panics, but the user is not able to pass in misspelled fields because the list of requested fields is always checked against a list of allowed fields. |
||
| return strings.EqualFold(f, s) | ||
| }) | ||
| data[f] = sf.Interface() | ||
| } | ||
| } | ||
|
|
||
| return &data | ||
| } | ||
|
|
||
| // ListCodespaces returns a list of codespaces for the user. Pass a negative limit to request all pages from | ||
| // the API until all codespaces have been fetched. | ||
| func (a *API) ListCodespaces(ctx context.Context, limit int) (codespaces []*Codespace, err error) { | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
All exported declarations should have a doc comment.