id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
9,300 | luci/luci-go | config/appengine/gaeconfig/validation.go | InstallValidationHandlers | func InstallValidationHandlers(r *router.Router, base router.MiddlewareChain, rules *validation.RuleSet) {
a := auth.Authenticator{
Methods: []auth.Method{
&server.OAuth2Method{Scopes: []string{server.EmailScope}},
},
}
base = base.Extend(a.GetMiddleware(), func(c *router.Context, next router.Handler) {
cc, w := c.Context, c.Writer
switch yep, err := isAuthorizedCall(cc, mustFetchCachedSettings(cc)); {
case err != nil:
errStatus(cc, w, err, http.StatusInternalServerError, "Unable to perform authorization")
case !yep:
errStatus(cc, w, nil, http.StatusForbidden, "Insufficient authority for validation")
default:
next(c)
}
})
validation.InstallHandlers(r, base, rules)
} | go | func InstallValidationHandlers(r *router.Router, base router.MiddlewareChain, rules *validation.RuleSet) {
a := auth.Authenticator{
Methods: []auth.Method{
&server.OAuth2Method{Scopes: []string{server.EmailScope}},
},
}
base = base.Extend(a.GetMiddleware(), func(c *router.Context, next router.Handler) {
cc, w := c.Context, c.Writer
switch yep, err := isAuthorizedCall(cc, mustFetchCachedSettings(cc)); {
case err != nil:
errStatus(cc, w, err, http.StatusInternalServerError, "Unable to perform authorization")
case !yep:
errStatus(cc, w, nil, http.StatusForbidden, "Insufficient authority for validation")
default:
next(c)
}
})
validation.InstallHandlers(r, base, rules)
} | [
"func",
"InstallValidationHandlers",
"(",
"r",
"*",
"router",
".",
"Router",
",",
"base",
"router",
".",
"MiddlewareChain",
",",
"rules",
"*",
"validation",
".",
"RuleSet",
")",
"{",
"a",
":=",
"auth",
".",
"Authenticator",
"{",
"Methods",
":",
"[",
"]",
"auth",
".",
"Method",
"{",
"&",
"server",
".",
"OAuth2Method",
"{",
"Scopes",
":",
"[",
"]",
"string",
"{",
"server",
".",
"EmailScope",
"}",
"}",
",",
"}",
",",
"}",
"\n",
"base",
"=",
"base",
".",
"Extend",
"(",
"a",
".",
"GetMiddleware",
"(",
")",
",",
"func",
"(",
"c",
"*",
"router",
".",
"Context",
",",
"next",
"router",
".",
"Handler",
")",
"{",
"cc",
",",
"w",
":=",
"c",
".",
"Context",
",",
"c",
".",
"Writer",
"\n",
"switch",
"yep",
",",
"err",
":=",
"isAuthorizedCall",
"(",
"cc",
",",
"mustFetchCachedSettings",
"(",
"cc",
")",
")",
";",
"{",
"case",
"err",
"!=",
"nil",
":",
"errStatus",
"(",
"cc",
",",
"w",
",",
"err",
",",
"http",
".",
"StatusInternalServerError",
",",
"\"",
"\"",
")",
"\n",
"case",
"!",
"yep",
":",
"errStatus",
"(",
"cc",
",",
"w",
",",
"nil",
",",
"http",
".",
"StatusForbidden",
",",
"\"",
"\"",
")",
"\n",
"default",
":",
"next",
"(",
"c",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"validation",
".",
"InstallHandlers",
"(",
"r",
",",
"base",
",",
"rules",
")",
"\n",
"}"
] | // InstallValidationHandlers installs handlers for config validation.
//
// It ensures that caller is either the config service itself or a member of a
// trusted group, both of which are configurable in the appengine app settings.
// It requires that the hostname, the email of config service and the name of
// the trusted group have been defined in the appengine app settings page before
// the installed endpoints are called. | [
"InstallValidationHandlers",
"installs",
"handlers",
"for",
"config",
"validation",
".",
"It",
"ensures",
"that",
"caller",
"is",
"either",
"the",
"config",
"service",
"itself",
"or",
"a",
"member",
"of",
"a",
"trusted",
"group",
"both",
"of",
"which",
"are",
"configurable",
"in",
"the",
"appengine",
"app",
"settings",
".",
"It",
"requires",
"that",
"the",
"hostname",
"the",
"email",
"of",
"config",
"service",
"and",
"the",
"name",
"of",
"the",
"trusted",
"group",
"have",
"been",
"defined",
"in",
"the",
"appengine",
"app",
"settings",
"page",
"before",
"the",
"installed",
"endpoints",
"are",
"called",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/config/appengine/gaeconfig/validation.go#L60-L78 |
9,301 | luci/luci-go | config/appengine/gaeconfig/validation.go | isAuthorizedCall | func isAuthorizedCall(c context.Context, s *Settings) (bool, error) {
// Someone from an admin group (if it is configured)? This is useful locally
// during development.
if s.AdministratorsGroup != "" {
switch yep, err := auth.IsMember(c, s.AdministratorsGroup); {
case err != nil:
return false, err
case yep:
return true, nil
}
}
// The config server itself (if it is configured)? May be empty when
// running stuff locally.
if s.ConfigServiceHost != "" {
info, err := signing.FetchServiceInfoFromLUCIService(c, "https://"+s.ConfigServiceHost)
if err != nil {
return false, err
}
caller := auth.CurrentIdentity(c)
if caller.Kind() == identity.User && caller.Value() == info.ServiceAccountName {
return true, nil
}
}
// A total stranger.
return false, nil
} | go | func isAuthorizedCall(c context.Context, s *Settings) (bool, error) {
// Someone from an admin group (if it is configured)? This is useful locally
// during development.
if s.AdministratorsGroup != "" {
switch yep, err := auth.IsMember(c, s.AdministratorsGroup); {
case err != nil:
return false, err
case yep:
return true, nil
}
}
// The config server itself (if it is configured)? May be empty when
// running stuff locally.
if s.ConfigServiceHost != "" {
info, err := signing.FetchServiceInfoFromLUCIService(c, "https://"+s.ConfigServiceHost)
if err != nil {
return false, err
}
caller := auth.CurrentIdentity(c)
if caller.Kind() == identity.User && caller.Value() == info.ServiceAccountName {
return true, nil
}
}
// A total stranger.
return false, nil
} | [
"func",
"isAuthorizedCall",
"(",
"c",
"context",
".",
"Context",
",",
"s",
"*",
"Settings",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Someone from an admin group (if it is configured)? This is useful locally",
"// during development.",
"if",
"s",
".",
"AdministratorsGroup",
"!=",
"\"",
"\"",
"{",
"switch",
"yep",
",",
"err",
":=",
"auth",
".",
"IsMember",
"(",
"c",
",",
"s",
".",
"AdministratorsGroup",
")",
";",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"false",
",",
"err",
"\n",
"case",
"yep",
":",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// The config server itself (if it is configured)? May be empty when",
"// running stuff locally.",
"if",
"s",
".",
"ConfigServiceHost",
"!=",
"\"",
"\"",
"{",
"info",
",",
"err",
":=",
"signing",
".",
"FetchServiceInfoFromLUCIService",
"(",
"c",
",",
"\"",
"\"",
"+",
"s",
".",
"ConfigServiceHost",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"caller",
":=",
"auth",
".",
"CurrentIdentity",
"(",
"c",
")",
"\n",
"if",
"caller",
".",
"Kind",
"(",
")",
"==",
"identity",
".",
"User",
"&&",
"caller",
".",
"Value",
"(",
")",
"==",
"info",
".",
"ServiceAccountName",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// A total stranger.",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // isAuthorizedCall returns true if the current caller is allowed to call the
// config validation endpoints.
//
// This is either the service account of the config service, or someone from
// an admin group. | [
"isAuthorizedCall",
"returns",
"true",
"if",
"the",
"current",
"caller",
"is",
"allowed",
"to",
"call",
"the",
"config",
"validation",
"endpoints",
".",
"This",
"is",
"either",
"the",
"service",
"account",
"of",
"the",
"config",
"service",
"or",
"someone",
"from",
"an",
"admin",
"group",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/config/appengine/gaeconfig/validation.go#L96-L123 |
9,302 | luci/luci-go | config/appengine/gaeconfig/validation.go | GetConfigServiceAppID | func GetConfigServiceAppID(c context.Context) (string, error) {
s, err := FetchCachedSettings(c)
switch {
case err != nil:
return "", err
case s.ConfigServiceHost == "":
return "", nil
}
info, err := signing.FetchServiceInfoFromLUCIService(c, "https://"+s.ConfigServiceHost)
if err != nil {
return "", err
}
return info.AppID, nil
} | go | func GetConfigServiceAppID(c context.Context) (string, error) {
s, err := FetchCachedSettings(c)
switch {
case err != nil:
return "", err
case s.ConfigServiceHost == "":
return "", nil
}
info, err := signing.FetchServiceInfoFromLUCIService(c, "https://"+s.ConfigServiceHost)
if err != nil {
return "", err
}
return info.AppID, nil
} | [
"func",
"GetConfigServiceAppID",
"(",
"c",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"FetchCachedSettings",
"(",
"c",
")",
"\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"\"",
"\"",
",",
"err",
"\n",
"case",
"s",
".",
"ConfigServiceHost",
"==",
"\"",
"\"",
":",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"info",
",",
"err",
":=",
"signing",
".",
"FetchServiceInfoFromLUCIService",
"(",
"c",
",",
"\"",
"\"",
"+",
"s",
".",
"ConfigServiceHost",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"info",
".",
"AppID",
",",
"nil",
"\n",
"}"
] | // GetConfigServiceAppID looks up the app ID of the LUCI Config service, as set
// in the app's settings.
//
// Returns an empty string if the LUCI Config integration is not configured for
// the app. | [
"GetConfigServiceAppID",
"looks",
"up",
"the",
"app",
"ID",
"of",
"the",
"LUCI",
"Config",
"service",
"as",
"set",
"in",
"the",
"app",
"s",
"settings",
".",
"Returns",
"an",
"empty",
"string",
"if",
"the",
"LUCI",
"Config",
"integration",
"is",
"not",
"configured",
"for",
"the",
"app",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/config/appengine/gaeconfig/validation.go#L130-L143 |
9,303 | luci/luci-go | cipd/appengine/impl/cas/acled.go | Public | func Public(internal api.StorageServer) api.StorageServer {
return &api.DecoratedStorage{
Service: internal,
Prelude: aclPrelude,
}
} | go | func Public(internal api.StorageServer) api.StorageServer {
return &api.DecoratedStorage{
Service: internal,
Prelude: aclPrelude,
}
} | [
"func",
"Public",
"(",
"internal",
"api",
".",
"StorageServer",
")",
"api",
".",
"StorageServer",
"{",
"return",
"&",
"api",
".",
"DecoratedStorage",
"{",
"Service",
":",
"internal",
",",
"Prelude",
":",
"aclPrelude",
",",
"}",
"\n",
"}"
] | // Public returns publicly exposed implementation of cipd.Storage service that
// wraps the given internal implementation with ACLs. | [
"Public",
"returns",
"publicly",
"exposed",
"implementation",
"of",
"cipd",
".",
"Storage",
"service",
"that",
"wraps",
"the",
"given",
"internal",
"implementation",
"with",
"ACLs",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/appengine/impl/cas/acled.go#L34-L39 |
9,304 | luci/luci-go | cipd/appengine/impl/cas/acled.go | aclPrelude | func aclPrelude(c context.Context, methodName string, req proto.Message) (context.Context, error) {
acl, ok := perMethodACL[methodName]
if !ok {
panic(fmt.Sprintf("method %q is not defined in perMethodACL", methodName))
}
if acl.group != "*" {
switch yep, err := auth.IsMember(c, acl.group); {
case err != nil:
logging.WithError(err).Errorf(c, "IsMember(%q) failed", acl.group)
return nil, status.Errorf(codes.Internal, "failed to check ACL")
case !yep:
return nil, status.Errorf(codes.PermissionDenied, "not allowed")
}
}
if acl.check != nil {
if err := acl.check(c, req); err != nil {
return nil, err
}
}
return c, nil
} | go | func aclPrelude(c context.Context, methodName string, req proto.Message) (context.Context, error) {
acl, ok := perMethodACL[methodName]
if !ok {
panic(fmt.Sprintf("method %q is not defined in perMethodACL", methodName))
}
if acl.group != "*" {
switch yep, err := auth.IsMember(c, acl.group); {
case err != nil:
logging.WithError(err).Errorf(c, "IsMember(%q) failed", acl.group)
return nil, status.Errorf(codes.Internal, "failed to check ACL")
case !yep:
return nil, status.Errorf(codes.PermissionDenied, "not allowed")
}
}
if acl.check != nil {
if err := acl.check(c, req); err != nil {
return nil, err
}
}
return c, nil
} | [
"func",
"aclPrelude",
"(",
"c",
"context",
".",
"Context",
",",
"methodName",
"string",
",",
"req",
"proto",
".",
"Message",
")",
"(",
"context",
".",
"Context",
",",
"error",
")",
"{",
"acl",
",",
"ok",
":=",
"perMethodACL",
"[",
"methodName",
"]",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"methodName",
")",
")",
"\n",
"}",
"\n",
"if",
"acl",
".",
"group",
"!=",
"\"",
"\"",
"{",
"switch",
"yep",
",",
"err",
":=",
"auth",
".",
"IsMember",
"(",
"c",
",",
"acl",
".",
"group",
")",
";",
"{",
"case",
"err",
"!=",
"nil",
":",
"logging",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"c",
",",
"\"",
"\"",
",",
"acl",
".",
"group",
")",
"\n",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
")",
"\n",
"case",
"!",
"yep",
":",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"PermissionDenied",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"acl",
".",
"check",
"!=",
"nil",
"{",
"if",
"err",
":=",
"acl",
".",
"check",
"(",
"c",
",",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // aclPrelude is called before each RPC to check ACLs. | [
"aclPrelude",
"is",
"called",
"before",
"each",
"RPC",
"to",
"check",
"ACLs",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/appengine/impl/cas/acled.go#L42-L62 |
9,305 | luci/luci-go | lucicfg/native.go | unpack | func (c *nativeCall) unpack(min int, vars ...interface{}) error {
return starlark.UnpackPositionalArgs(c.Fn.Name(), c.Args, c.Kwargs, min, vars...)
} | go | func (c *nativeCall) unpack(min int, vars ...interface{}) error {
return starlark.UnpackPositionalArgs(c.Fn.Name(), c.Args, c.Kwargs, min, vars...)
} | [
"func",
"(",
"c",
"*",
"nativeCall",
")",
"unpack",
"(",
"min",
"int",
",",
"vars",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"starlark",
".",
"UnpackPositionalArgs",
"(",
"c",
".",
"Fn",
".",
"Name",
"(",
")",
",",
"c",
".",
"Args",
",",
"c",
".",
"Kwargs",
",",
"min",
",",
"vars",
"...",
")",
"\n",
"}"
] | // unpack unpacks the positional arguments into corresponding variables.
//
// See starlark.UnpackPositionalArgs for more info. | [
"unpack",
"unpacks",
"the",
"positional",
"arguments",
"into",
"corresponding",
"variables",
".",
"See",
"starlark",
".",
"UnpackPositionalArgs",
"for",
"more",
"info",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/lucicfg/native.go#L41-L43 |
9,306 | luci/luci-go | dm/appengine/model/keys.go | QuestKeyFromID | func QuestKeyFromID(c context.Context, qid string) *ds.Key {
return ds.MakeKey(c, "Quest", qid)
} | go | func QuestKeyFromID(c context.Context, qid string) *ds.Key {
return ds.MakeKey(c, "Quest", qid)
} | [
"func",
"QuestKeyFromID",
"(",
"c",
"context",
".",
"Context",
",",
"qid",
"string",
")",
"*",
"ds",
".",
"Key",
"{",
"return",
"ds",
".",
"MakeKey",
"(",
"c",
",",
"\"",
"\"",
",",
"qid",
")",
"\n",
"}"
] | // QuestKeyFromID makes a datastore.Key given the QuestID. | [
"QuestKeyFromID",
"makes",
"a",
"datastore",
".",
"Key",
"given",
"the",
"QuestID",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L27-L29 |
9,307 | luci/luci-go | dm/appengine/model/keys.go | QuestIDFromKey | func QuestIDFromKey(k *ds.Key) string {
if k.Kind() != "Quest" || k.Parent() != nil {
panic(fmt.Errorf("invalid Quest key: %s", k))
}
return k.StringID()
} | go | func QuestIDFromKey(k *ds.Key) string {
if k.Kind() != "Quest" || k.Parent() != nil {
panic(fmt.Errorf("invalid Quest key: %s", k))
}
return k.StringID()
} | [
"func",
"QuestIDFromKey",
"(",
"k",
"*",
"ds",
".",
"Key",
")",
"string",
"{",
"if",
"k",
".",
"Kind",
"(",
")",
"!=",
"\"",
"\"",
"||",
"k",
".",
"Parent",
"(",
")",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
")",
"\n",
"}",
"\n",
"return",
"k",
".",
"StringID",
"(",
")",
"\n",
"}"
] | // QuestIDFromKey makes a QuestID from the given datastore.Key. It panics if the
// Key does not point to a Quest. | [
"QuestIDFromKey",
"makes",
"a",
"QuestID",
"from",
"the",
"given",
"datastore",
".",
"Key",
".",
"It",
"panics",
"if",
"the",
"Key",
"does",
"not",
"point",
"to",
"a",
"Quest",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L38-L43 |
9,308 | luci/luci-go | dm/appengine/model/keys.go | AttemptKeyFromID | func AttemptKeyFromID(c context.Context, aid *dm.Attempt_ID) *ds.Key {
return ds.MakeKey(c, "Attempt", aid.DMEncoded())
} | go | func AttemptKeyFromID(c context.Context, aid *dm.Attempt_ID) *ds.Key {
return ds.MakeKey(c, "Attempt", aid.DMEncoded())
} | [
"func",
"AttemptKeyFromID",
"(",
"c",
"context",
".",
"Context",
",",
"aid",
"*",
"dm",
".",
"Attempt_ID",
")",
"*",
"ds",
".",
"Key",
"{",
"return",
"ds",
".",
"MakeKey",
"(",
"c",
",",
"\"",
"\"",
",",
"aid",
".",
"DMEncoded",
"(",
")",
")",
"\n",
"}"
] | // AttemptKeyFromID makes a datastore.Key given the AttemptID. | [
"AttemptKeyFromID",
"makes",
"a",
"datastore",
".",
"Key",
"given",
"the",
"AttemptID",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L46-L48 |
9,309 | luci/luci-go | dm/appengine/model/keys.go | AttemptFromID | func AttemptFromID(aid *dm.Attempt_ID) *Attempt {
ret := &Attempt{}
ret.ID = *aid
return ret
} | go | func AttemptFromID(aid *dm.Attempt_ID) *Attempt {
ret := &Attempt{}
ret.ID = *aid
return ret
} | [
"func",
"AttemptFromID",
"(",
"aid",
"*",
"dm",
".",
"Attempt_ID",
")",
"*",
"Attempt",
"{",
"ret",
":=",
"&",
"Attempt",
"{",
"}",
"\n",
"ret",
".",
"ID",
"=",
"*",
"aid",
"\n",
"return",
"ret",
"\n",
"}"
] | // AttemptFromID produces an empty Attempt model from the AttemptID. | [
"AttemptFromID",
"produces",
"an",
"empty",
"Attempt",
"model",
"from",
"the",
"AttemptID",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L51-L55 |
9,310 | luci/luci-go | dm/appengine/model/keys.go | AttemptIDFromKey | func AttemptIDFromKey(k *ds.Key) *dm.Attempt_ID {
if k.Kind() != "Attempt" || k.Parent() != nil {
panic(fmt.Errorf("invalid Attempt key: %s", k))
}
ret := &dm.Attempt_ID{}
if err := ret.SetDMEncoded(k.StringID()); err != nil {
panic(fmt.Errorf("invalid Attempt key: %s: %s", k, err))
}
return ret
} | go | func AttemptIDFromKey(k *ds.Key) *dm.Attempt_ID {
if k.Kind() != "Attempt" || k.Parent() != nil {
panic(fmt.Errorf("invalid Attempt key: %s", k))
}
ret := &dm.Attempt_ID{}
if err := ret.SetDMEncoded(k.StringID()); err != nil {
panic(fmt.Errorf("invalid Attempt key: %s: %s", k, err))
}
return ret
} | [
"func",
"AttemptIDFromKey",
"(",
"k",
"*",
"ds",
".",
"Key",
")",
"*",
"dm",
".",
"Attempt_ID",
"{",
"if",
"k",
".",
"Kind",
"(",
")",
"!=",
"\"",
"\"",
"||",
"k",
".",
"Parent",
"(",
")",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
")",
"\n",
"}",
"\n",
"ret",
":=",
"&",
"dm",
".",
"Attempt_ID",
"{",
"}",
"\n",
"if",
"err",
":=",
"ret",
".",
"SetDMEncoded",
"(",
"k",
".",
"StringID",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] | // AttemptIDFromKey makes a AttemptID from the given datastore.Key. It panics if the
// Key does not point to a Attempt. | [
"AttemptIDFromKey",
"makes",
"a",
"AttemptID",
"from",
"the",
"given",
"datastore",
".",
"Key",
".",
"It",
"panics",
"if",
"the",
"Key",
"does",
"not",
"point",
"to",
"a",
"Attempt",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L59-L68 |
9,311 | luci/luci-go | dm/appengine/model/keys.go | ExecutionKeyFromID | func ExecutionKeyFromID(c context.Context, eid *dm.Execution_ID) *ds.Key {
return ds.MakeKey(c, "Attempt", eid.AttemptID().DMEncoded(), "Execution", eid.Id)
} | go | func ExecutionKeyFromID(c context.Context, eid *dm.Execution_ID) *ds.Key {
return ds.MakeKey(c, "Attempt", eid.AttemptID().DMEncoded(), "Execution", eid.Id)
} | [
"func",
"ExecutionKeyFromID",
"(",
"c",
"context",
".",
"Context",
",",
"eid",
"*",
"dm",
".",
"Execution_ID",
")",
"*",
"ds",
".",
"Key",
"{",
"return",
"ds",
".",
"MakeKey",
"(",
"c",
",",
"\"",
"\"",
",",
"eid",
".",
"AttemptID",
"(",
")",
".",
"DMEncoded",
"(",
")",
",",
"\"",
"\"",
",",
"eid",
".",
"Id",
")",
"\n",
"}"
] | // ExecutionKeyFromID makes a datastore.Key given the ExecutionID. | [
"ExecutionKeyFromID",
"makes",
"a",
"datastore",
".",
"Key",
"given",
"the",
"ExecutionID",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L71-L73 |
9,312 | luci/luci-go | dm/appengine/model/keys.go | ExecutionFromID | func ExecutionFromID(c context.Context, eid *dm.Execution_ID) *Execution {
ret := &Execution{}
ret.ID = invertedHexUint32(eid.Id)
ret.Attempt = AttemptKeyFromID(c, eid.AttemptID())
return ret
} | go | func ExecutionFromID(c context.Context, eid *dm.Execution_ID) *Execution {
ret := &Execution{}
ret.ID = invertedHexUint32(eid.Id)
ret.Attempt = AttemptKeyFromID(c, eid.AttemptID())
return ret
} | [
"func",
"ExecutionFromID",
"(",
"c",
"context",
".",
"Context",
",",
"eid",
"*",
"dm",
".",
"Execution_ID",
")",
"*",
"Execution",
"{",
"ret",
":=",
"&",
"Execution",
"{",
"}",
"\n",
"ret",
".",
"ID",
"=",
"invertedHexUint32",
"(",
"eid",
".",
"Id",
")",
"\n",
"ret",
".",
"Attempt",
"=",
"AttemptKeyFromID",
"(",
"c",
",",
"eid",
".",
"AttemptID",
"(",
")",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // ExecutionFromID produces an empty Execution model from the ExecutionID. | [
"ExecutionFromID",
"produces",
"an",
"empty",
"Execution",
"model",
"from",
"the",
"ExecutionID",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L76-L81 |
9,313 | luci/luci-go | dm/appengine/model/keys.go | ExecutionIDFromKey | func ExecutionIDFromKey(k *ds.Key) *dm.Execution_ID {
if k.Kind() != "Execution" || k.Parent() == nil {
panic(fmt.Errorf("invalid Execution key: %s", k))
}
id := k.IntID()
if id <= 0 || id > math.MaxUint32 {
panic(fmt.Errorf("invalid Execution key: %s", k))
}
atmpt := AttemptIDFromKey(k.Parent())
return &dm.Execution_ID{Quest: atmpt.Quest, Attempt: atmpt.Id, Id: uint32(id)}
} | go | func ExecutionIDFromKey(k *ds.Key) *dm.Execution_ID {
if k.Kind() != "Execution" || k.Parent() == nil {
panic(fmt.Errorf("invalid Execution key: %s", k))
}
id := k.IntID()
if id <= 0 || id > math.MaxUint32 {
panic(fmt.Errorf("invalid Execution key: %s", k))
}
atmpt := AttemptIDFromKey(k.Parent())
return &dm.Execution_ID{Quest: atmpt.Quest, Attempt: atmpt.Id, Id: uint32(id)}
} | [
"func",
"ExecutionIDFromKey",
"(",
"k",
"*",
"ds",
".",
"Key",
")",
"*",
"dm",
".",
"Execution_ID",
"{",
"if",
"k",
".",
"Kind",
"(",
")",
"!=",
"\"",
"\"",
"||",
"k",
".",
"Parent",
"(",
")",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
")",
"\n",
"}",
"\n",
"id",
":=",
"k",
".",
"IntID",
"(",
")",
"\n",
"if",
"id",
"<=",
"0",
"||",
"id",
">",
"math",
".",
"MaxUint32",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
")",
"\n",
"}",
"\n",
"atmpt",
":=",
"AttemptIDFromKey",
"(",
"k",
".",
"Parent",
"(",
")",
")",
"\n",
"return",
"&",
"dm",
".",
"Execution_ID",
"{",
"Quest",
":",
"atmpt",
".",
"Quest",
",",
"Attempt",
":",
"atmpt",
".",
"Id",
",",
"Id",
":",
"uint32",
"(",
"id",
")",
"}",
"\n",
"}"
] | // ExecutionIDFromKey makes a ExecutionID from the given datastore.Key. It panics if the
// Key does not point to a Execution. | [
"ExecutionIDFromKey",
"makes",
"a",
"ExecutionID",
"from",
"the",
"given",
"datastore",
".",
"Key",
".",
"It",
"panics",
"if",
"the",
"Key",
"does",
"not",
"point",
"to",
"a",
"Execution",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/dm/appengine/model/keys.go#L85-L95 |
9,314 | luci/luci-go | mmutex/cmd/mmutex/command_helpers.go | runCommand | func runCommand(ctx context.Context, command []string) error {
cmd := exec.Command(command[0], command[1:]...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
} | go | func runCommand(ctx context.Context, command []string) error {
cmd := exec.Command(command[0], command[1:]...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
} | [
"func",
"runCommand",
"(",
"ctx",
"context",
".",
"Context",
",",
"command",
"[",
"]",
"string",
")",
"error",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"command",
"[",
"0",
"]",
",",
"command",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"return",
"cmd",
".",
"Run",
"(",
")",
"\n",
"}"
] | // Runs the command in the given context and returns any error that occurred. | [
"Runs",
"the",
"command",
"in",
"the",
"given",
"context",
"and",
"returns",
"any",
"error",
"that",
"occurred",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/mmutex/cmd/mmutex/command_helpers.go#L24-L29 |
9,315 | luci/luci-go | milo/api/buildbot/time.go | MarshalJSON | func (t *Time) MarshalJSON() ([]byte, error) {
var buildbotFormat *float64
if !t.Time.IsZero() {
usec := t.Time.Nanosecond() / 1e3
// avoid dividing big floating numbers
v := float64(t.Time.Unix()) + float64(usec)/1e6
buildbotFormat = &v
}
return json.Marshal(&buildbotFormat)
} | go | func (t *Time) MarshalJSON() ([]byte, error) {
var buildbotFormat *float64
if !t.Time.IsZero() {
usec := t.Time.Nanosecond() / 1e3
// avoid dividing big floating numbers
v := float64(t.Time.Unix()) + float64(usec)/1e6
buildbotFormat = &v
}
return json.Marshal(&buildbotFormat)
} | [
"func",
"(",
"t",
"*",
"Time",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buildbotFormat",
"*",
"float64",
"\n",
"if",
"!",
"t",
".",
"Time",
".",
"IsZero",
"(",
")",
"{",
"usec",
":=",
"t",
".",
"Time",
".",
"Nanosecond",
"(",
")",
"/",
"1e3",
"\n",
"// avoid dividing big floating numbers",
"v",
":=",
"float64",
"(",
"t",
".",
"Time",
".",
"Unix",
"(",
")",
")",
"+",
"float64",
"(",
"usec",
")",
"/",
"1e6",
"\n",
"buildbotFormat",
"=",
"&",
"v",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"&",
"buildbotFormat",
")",
"\n",
"}"
] | // MarshalJSON marshals t to JSON at microsecond resolution. | [
"MarshalJSON",
"marshals",
"t",
"to",
"JSON",
"at",
"microsecond",
"resolution",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/api/buildbot/time.go#L29-L38 |
9,316 | luci/luci-go | milo/api/buildbot/time.go | UnmarshalJSON | func (t *Time) UnmarshalJSON(data []byte) error {
var buildbotFormat *float64
err := json.Unmarshal(data, &buildbotFormat)
if err != nil {
return err
}
*t = Time{}
if buildbotFormat != nil {
sec := *buildbotFormat
usec := int64(sec*1e6) % 1e6
t.Time = time.Unix(int64(sec), usec*1e3).UTC()
}
return nil
} | go | func (t *Time) UnmarshalJSON(data []byte) error {
var buildbotFormat *float64
err := json.Unmarshal(data, &buildbotFormat)
if err != nil {
return err
}
*t = Time{}
if buildbotFormat != nil {
sec := *buildbotFormat
usec := int64(sec*1e6) % 1e6
t.Time = time.Unix(int64(sec), usec*1e3).UTC()
}
return nil
} | [
"func",
"(",
"t",
"*",
"Time",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"buildbotFormat",
"*",
"float64",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"buildbotFormat",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"*",
"t",
"=",
"Time",
"{",
"}",
"\n",
"if",
"buildbotFormat",
"!=",
"nil",
"{",
"sec",
":=",
"*",
"buildbotFormat",
"\n",
"usec",
":=",
"int64",
"(",
"sec",
"*",
"1e6",
")",
"%",
"1e6",
"\n",
"t",
".",
"Time",
"=",
"time",
".",
"Unix",
"(",
"int64",
"(",
"sec",
")",
",",
"usec",
"*",
"1e3",
")",
".",
"UTC",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON unmarshals t from JSON at microsecond resolution. | [
"UnmarshalJSON",
"unmarshals",
"t",
"from",
"JSON",
"at",
"microsecond",
"resolution",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/api/buildbot/time.go#L41-L54 |
9,317 | luci/luci-go | common/tsmon/metric/metric.go | NewInt | func NewInt(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Int {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &intMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeIntType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | go | func NewInt(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Int {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &intMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeIntType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | [
"func",
"NewInt",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"Int",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"intMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"NonCumulativeIntType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewInt returns a new non-cumulative integer gauge metric. | [
"NewInt",
"returns",
"a",
"new",
"non",
"-",
"cumulative",
"integer",
"gauge",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L114-L129 |
9,318 | luci/luci-go | common/tsmon/metric/metric.go | NewCounter | func NewCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Counter {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &counter{intMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeIntType,
},
MetricMetadata: *metadata,
}}}
registry.Add(m)
return m
} | go | func NewCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Counter {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &counter{intMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeIntType,
},
MetricMetadata: *metadata,
}}}
registry.Add(m)
return m
} | [
"func",
"NewCounter",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"Counter",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"counter",
"{",
"intMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"CumulativeIntType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewCounter returns a new cumulative integer metric. | [
"NewCounter",
"returns",
"a",
"new",
"cumulative",
"integer",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L132-L147 |
9,319 | luci/luci-go | common/tsmon/metric/metric.go | NewFloat | func NewFloat(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Float {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &floatMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeFloatType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | go | func NewFloat(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Float {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &floatMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeFloatType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | [
"func",
"NewFloat",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"Float",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"floatMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"NonCumulativeFloatType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewFloat returns a new non-cumulative floating-point gauge metric. | [
"NewFloat",
"returns",
"a",
"new",
"non",
"-",
"cumulative",
"floating",
"-",
"point",
"gauge",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L150-L165 |
9,320 | luci/luci-go | common/tsmon/metric/metric.go | NewFloatCounter | func NewFloatCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) FloatCounter {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &floatCounter{floatMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeFloatType,
},
MetricMetadata: *metadata,
}}}
registry.Add(m)
return m
} | go | func NewFloatCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) FloatCounter {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &floatCounter{floatMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeFloatType,
},
MetricMetadata: *metadata,
}}}
registry.Add(m)
return m
} | [
"func",
"NewFloatCounter",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"FloatCounter",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"floatCounter",
"{",
"floatMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"CumulativeFloatType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewFloatCounter returns a new cumulative floating-point metric. | [
"NewFloatCounter",
"returns",
"a",
"new",
"cumulative",
"floating",
"-",
"point",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L168-L183 |
9,321 | luci/luci-go | common/tsmon/metric/metric.go | NewString | func NewString(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) String {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &stringMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.StringType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | go | func NewString(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) String {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &stringMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.StringType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | [
"func",
"NewString",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"String",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"stringMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"StringType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewString returns a new string-valued metric. | [
"NewString",
"returns",
"a",
"new",
"string",
"-",
"valued",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L186-L201 |
9,322 | luci/luci-go | common/tsmon/metric/metric.go | NewBool | func NewBool(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Bool {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &boolMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.BoolType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | go | func NewBool(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Bool {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &boolMetric{metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.BoolType,
},
MetricMetadata: *metadata,
}}
registry.Add(m)
return m
} | [
"func",
"NewBool",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"Bool",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"boolMetric",
"{",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"BoolType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewBool returns a new bool-valued metric. | [
"NewBool",
"returns",
"a",
"new",
"bool",
"-",
"valued",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L204-L219 |
9,323 | luci/luci-go | common/tsmon/metric/metric.go | NewCumulativeDistribution | func NewCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CumulativeDistribution {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &cumulativeDistributionMetric{
nonCumulativeDistributionMetric{
metric: metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeDistributionType,
},
MetricMetadata: *metadata,
},
bucketer: bucketer,
},
}
registry.Add(m)
return m
} | go | func NewCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CumulativeDistribution {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &cumulativeDistributionMetric{
nonCumulativeDistributionMetric{
metric: metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.CumulativeDistributionType,
},
MetricMetadata: *metadata,
},
bucketer: bucketer,
},
}
registry.Add(m)
return m
} | [
"func",
"NewCumulativeDistribution",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"bucketer",
"*",
"distribution",
".",
"Bucketer",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"CumulativeDistribution",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"cumulativeDistributionMetric",
"{",
"nonCumulativeDistributionMetric",
"{",
"metric",
":",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"CumulativeDistributionType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
",",
"bucketer",
":",
"bucketer",
",",
"}",
",",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewCumulativeDistribution returns a new cumulative-distribution-valued
// metric. | [
"NewCumulativeDistribution",
"returns",
"a",
"new",
"cumulative",
"-",
"distribution",
"-",
"valued",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L223-L243 |
9,324 | luci/luci-go | common/tsmon/metric/metric.go | NewNonCumulativeDistribution | func NewNonCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) NonCumulativeDistribution {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &nonCumulativeDistributionMetric{
metric: metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeDistributionType,
},
MetricMetadata: *metadata,
},
bucketer: bucketer,
}
registry.Add(m)
return m
} | go | func NewNonCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) NonCumulativeDistribution {
if metadata == nil {
metadata = &types.MetricMetadata{}
}
m := &nonCumulativeDistributionMetric{
metric: metric{
MetricInfo: types.MetricInfo{
Name: name,
Description: description,
Fields: fields,
ValueType: types.NonCumulativeDistributionType,
},
MetricMetadata: *metadata,
},
bucketer: bucketer,
}
registry.Add(m)
return m
} | [
"func",
"NewNonCumulativeDistribution",
"(",
"name",
"string",
",",
"description",
"string",
",",
"metadata",
"*",
"types",
".",
"MetricMetadata",
",",
"bucketer",
"*",
"distribution",
".",
"Bucketer",
",",
"fields",
"...",
"field",
".",
"Field",
")",
"NonCumulativeDistribution",
"{",
"if",
"metadata",
"==",
"nil",
"{",
"metadata",
"=",
"&",
"types",
".",
"MetricMetadata",
"{",
"}",
"\n",
"}",
"\n",
"m",
":=",
"&",
"nonCumulativeDistributionMetric",
"{",
"metric",
":",
"metric",
"{",
"MetricInfo",
":",
"types",
".",
"MetricInfo",
"{",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Fields",
":",
"fields",
",",
"ValueType",
":",
"types",
".",
"NonCumulativeDistributionType",
",",
"}",
",",
"MetricMetadata",
":",
"*",
"metadata",
",",
"}",
",",
"bucketer",
":",
"bucketer",
",",
"}",
"\n",
"registry",
".",
"Add",
"(",
"m",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewNonCumulativeDistribution returns a new non-cumulative-distribution-valued
// metric. | [
"NewNonCumulativeDistribution",
"returns",
"a",
"new",
"non",
"-",
"cumulative",
"-",
"distribution",
"-",
"valued",
"metric",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L247-L265 |
9,325 | luci/luci-go | common/tsmon/metric/metric.go | genericGet | func (m *metric) genericGet(zero interface{}, c context.Context, fieldVals []interface{}) interface{} {
if ret := tsmon.Store(c).Get(c, m, m.fixedResetTime, fieldVals); ret != nil {
return ret
}
return zero
} | go | func (m *metric) genericGet(zero interface{}, c context.Context, fieldVals []interface{}) interface{} {
if ret := tsmon.Store(c).Get(c, m, m.fixedResetTime, fieldVals); ret != nil {
return ret
}
return zero
} | [
"func",
"(",
"m",
"*",
"metric",
")",
"genericGet",
"(",
"zero",
"interface",
"{",
"}",
",",
"c",
"context",
".",
"Context",
",",
"fieldVals",
"[",
"]",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"ret",
":=",
"tsmon",
".",
"Store",
"(",
"c",
")",
".",
"Get",
"(",
"c",
",",
"m",
",",
"m",
".",
"fixedResetTime",
",",
"fieldVals",
")",
";",
"ret",
"!=",
"nil",
"{",
"return",
"ret",
"\n",
"}",
"\n",
"return",
"zero",
"\n",
"}"
] | // genericGet is a convenience function that tries to get a metric value from
// the store and returns the zero value if it didn't exist. | [
"genericGet",
"is",
"a",
"convenience",
"function",
"that",
"tries",
"to",
"get",
"a",
"metric",
"value",
"from",
"the",
"store",
"and",
"returns",
"the",
"zero",
"value",
"if",
"it",
"didn",
"t",
"exist",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/metric/metric.go#L269-L274 |
9,326 | luci/luci-go | scheduler/appengine/engine/policy/request_builder.go | DebugLog | func (r *RequestBuilder) DebugLog(format string, args ...interface{}) {
r.Request.DebugLog += fmt.Sprintf(format+"\n", args...)
if r.env != nil {
r.env.DebugLog(format, args...)
}
} | go | func (r *RequestBuilder) DebugLog(format string, args ...interface{}) {
r.Request.DebugLog += fmt.Sprintf(format+"\n", args...)
if r.env != nil {
r.env.DebugLog(format, args...)
}
} | [
"func",
"(",
"r",
"*",
"RequestBuilder",
")",
"DebugLog",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"r",
".",
"Request",
".",
"DebugLog",
"+=",
"fmt",
".",
"Sprintf",
"(",
"format",
"+",
"\"",
"\\n",
"\"",
",",
"args",
"...",
")",
"\n",
"if",
"r",
".",
"env",
"!=",
"nil",
"{",
"r",
".",
"env",
".",
"DebugLog",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"}"
] | // DebugLog adds a line to the request log and the triage log. | [
"DebugLog",
"adds",
"a",
"line",
"to",
"the",
"request",
"log",
"and",
"the",
"triage",
"log",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/scheduler/appengine/engine/policy/request_builder.go#L41-L46 |
9,327 | luci/luci-go | scheduler/appengine/engine/policy/request_builder.go | FromTrigger | func (r *RequestBuilder) FromTrigger(t *internal.Trigger) {
switch p := t.Payload.(type) {
case *internal.Trigger_Cron:
r.FromCronTrigger(p.Cron)
case *internal.Trigger_Webui:
r.FromWebUITrigger(p.Webui)
case *internal.Trigger_Noop:
r.FromNoopTrigger(p.Noop)
case *internal.Trigger_Gitiles:
r.FromGitilesTrigger(p.Gitiles)
case *internal.Trigger_Buildbucket:
r.FromBuildbucketTrigger(p.Buildbucket)
default:
r.DebugLog("Unrecognized trigger payload of type %T, ignoring", p)
}
} | go | func (r *RequestBuilder) FromTrigger(t *internal.Trigger) {
switch p := t.Payload.(type) {
case *internal.Trigger_Cron:
r.FromCronTrigger(p.Cron)
case *internal.Trigger_Webui:
r.FromWebUITrigger(p.Webui)
case *internal.Trigger_Noop:
r.FromNoopTrigger(p.Noop)
case *internal.Trigger_Gitiles:
r.FromGitilesTrigger(p.Gitiles)
case *internal.Trigger_Buildbucket:
r.FromBuildbucketTrigger(p.Buildbucket)
default:
r.DebugLog("Unrecognized trigger payload of type %T, ignoring", p)
}
} | [
"func",
"(",
"r",
"*",
"RequestBuilder",
")",
"FromTrigger",
"(",
"t",
"*",
"internal",
".",
"Trigger",
")",
"{",
"switch",
"p",
":=",
"t",
".",
"Payload",
".",
"(",
"type",
")",
"{",
"case",
"*",
"internal",
".",
"Trigger_Cron",
":",
"r",
".",
"FromCronTrigger",
"(",
"p",
".",
"Cron",
")",
"\n",
"case",
"*",
"internal",
".",
"Trigger_Webui",
":",
"r",
".",
"FromWebUITrigger",
"(",
"p",
".",
"Webui",
")",
"\n",
"case",
"*",
"internal",
".",
"Trigger_Noop",
":",
"r",
".",
"FromNoopTrigger",
"(",
"p",
".",
"Noop",
")",
"\n",
"case",
"*",
"internal",
".",
"Trigger_Gitiles",
":",
"r",
".",
"FromGitilesTrigger",
"(",
"p",
".",
"Gitiles",
")",
"\n",
"case",
"*",
"internal",
".",
"Trigger_Buildbucket",
":",
"r",
".",
"FromBuildbucketTrigger",
"(",
"p",
".",
"Buildbucket",
")",
"\n",
"default",
":",
"r",
".",
"DebugLog",
"(",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n",
"}"
] | // FromTrigger derives the request properties from the given trigger. | [
"FromTrigger",
"derives",
"the",
"request",
"properties",
"from",
"the",
"given",
"trigger",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/scheduler/appengine/engine/policy/request_builder.go#L49-L64 |
9,328 | luci/luci-go | scheduler/appengine/engine/policy/request_builder.go | FromNoopTrigger | func (r *RequestBuilder) FromNoopTrigger(t *scheduler.NoopTrigger) {
r.Properties = structFromMap(map[string]string{
"noop_trigger_data": t.Data, // for testing
})
} | go | func (r *RequestBuilder) FromNoopTrigger(t *scheduler.NoopTrigger) {
r.Properties = structFromMap(map[string]string{
"noop_trigger_data": t.Data, // for testing
})
} | [
"func",
"(",
"r",
"*",
"RequestBuilder",
")",
"FromNoopTrigger",
"(",
"t",
"*",
"scheduler",
".",
"NoopTrigger",
")",
"{",
"r",
".",
"Properties",
"=",
"structFromMap",
"(",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"t",
".",
"Data",
",",
"// for testing",
"}",
")",
"\n",
"}"
] | // FromNoopTrigger derives the request properties from the given noop trigger. | [
"FromNoopTrigger",
"derives",
"the",
"request",
"properties",
"from",
"the",
"given",
"noop",
"trigger",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/scheduler/appengine/engine/policy/request_builder.go#L78-L82 |
9,329 | luci/luci-go | scheduler/appengine/engine/policy/request_builder.go | FromGitilesTrigger | func (r *RequestBuilder) FromGitilesTrigger(t *scheduler.GitilesTrigger) {
repo, err := gitiles.NormalizeRepoURL(t.Repo, false)
if err != nil {
r.DebugLog("Bad repo URL %q in the trigger - %s", t.Repo, err)
return
}
commit := &buildbucketpb.GitilesCommit{
Host: repo.Host,
Project: strings.TrimPrefix(repo.Path, "/"),
Id: t.Revision,
}
r.Properties = structFromMap(map[string]string{
"revision": t.Revision,
"branch": t.Ref,
"repository": t.Repo,
})
r.Tags = []string{
strpair.Format(bbv1.TagBuildSet, protoutil.GitilesBuildSet(commit)),
// TODO(nodir): remove after switching to ScheduleBuild RPC v2.
strpair.Format(bbv1.TagBuildSet, "commit/git/"+commit.Id),
strpair.Format("gitiles_ref", t.Ref),
}
} | go | func (r *RequestBuilder) FromGitilesTrigger(t *scheduler.GitilesTrigger) {
repo, err := gitiles.NormalizeRepoURL(t.Repo, false)
if err != nil {
r.DebugLog("Bad repo URL %q in the trigger - %s", t.Repo, err)
return
}
commit := &buildbucketpb.GitilesCommit{
Host: repo.Host,
Project: strings.TrimPrefix(repo.Path, "/"),
Id: t.Revision,
}
r.Properties = structFromMap(map[string]string{
"revision": t.Revision,
"branch": t.Ref,
"repository": t.Repo,
})
r.Tags = []string{
strpair.Format(bbv1.TagBuildSet, protoutil.GitilesBuildSet(commit)),
// TODO(nodir): remove after switching to ScheduleBuild RPC v2.
strpair.Format(bbv1.TagBuildSet, "commit/git/"+commit.Id),
strpair.Format("gitiles_ref", t.Ref),
}
} | [
"func",
"(",
"r",
"*",
"RequestBuilder",
")",
"FromGitilesTrigger",
"(",
"t",
"*",
"scheduler",
".",
"GitilesTrigger",
")",
"{",
"repo",
",",
"err",
":=",
"gitiles",
".",
"NormalizeRepoURL",
"(",
"t",
".",
"Repo",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"DebugLog",
"(",
"\"",
"\"",
",",
"t",
".",
"Repo",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"commit",
":=",
"&",
"buildbucketpb",
".",
"GitilesCommit",
"{",
"Host",
":",
"repo",
".",
"Host",
",",
"Project",
":",
"strings",
".",
"TrimPrefix",
"(",
"repo",
".",
"Path",
",",
"\"",
"\"",
")",
",",
"Id",
":",
"t",
".",
"Revision",
",",
"}",
"\n\n",
"r",
".",
"Properties",
"=",
"structFromMap",
"(",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"t",
".",
"Revision",
",",
"\"",
"\"",
":",
"t",
".",
"Ref",
",",
"\"",
"\"",
":",
"t",
".",
"Repo",
",",
"}",
")",
"\n",
"r",
".",
"Tags",
"=",
"[",
"]",
"string",
"{",
"strpair",
".",
"Format",
"(",
"bbv1",
".",
"TagBuildSet",
",",
"protoutil",
".",
"GitilesBuildSet",
"(",
"commit",
")",
")",
",",
"// TODO(nodir): remove after switching to ScheduleBuild RPC v2.",
"strpair",
".",
"Format",
"(",
"bbv1",
".",
"TagBuildSet",
",",
"\"",
"\"",
"+",
"commit",
".",
"Id",
")",
",",
"strpair",
".",
"Format",
"(",
"\"",
"\"",
",",
"t",
".",
"Ref",
")",
",",
"}",
"\n",
"}"
] | // FromGitilesTrigger derives the request properties from the given gitiles
// trigger. | [
"FromGitilesTrigger",
"derives",
"the",
"request",
"properties",
"from",
"the",
"given",
"gitiles",
"trigger",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/scheduler/appengine/engine/policy/request_builder.go#L86-L109 |
9,330 | luci/luci-go | scheduler/appengine/engine/policy/request_builder.go | FromBuildbucketTrigger | func (r *RequestBuilder) FromBuildbucketTrigger(t *scheduler.BuildbucketTrigger) {
r.Properties = t.Properties
r.Tags = t.Tags
} | go | func (r *RequestBuilder) FromBuildbucketTrigger(t *scheduler.BuildbucketTrigger) {
r.Properties = t.Properties
r.Tags = t.Tags
} | [
"func",
"(",
"r",
"*",
"RequestBuilder",
")",
"FromBuildbucketTrigger",
"(",
"t",
"*",
"scheduler",
".",
"BuildbucketTrigger",
")",
"{",
"r",
".",
"Properties",
"=",
"t",
".",
"Properties",
"\n",
"r",
".",
"Tags",
"=",
"t",
".",
"Tags",
"\n",
"}"
] | // FromBuildbucketTrigger derives the request properties from the given
// buildbucket trigger. | [
"FromBuildbucketTrigger",
"derives",
"the",
"request",
"properties",
"from",
"the",
"given",
"buildbucket",
"trigger",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/scheduler/appengine/engine/policy/request_builder.go#L113-L116 |
9,331 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | NewMockisBatchRequest_Request_Request | func NewMockisBatchRequest_Request_Request(ctrl *gomock.Controller) *MockisBatchRequest_Request_Request {
mock := &MockisBatchRequest_Request_Request{ctrl: ctrl}
mock.recorder = &MockisBatchRequest_Request_RequestMockRecorder{mock}
return mock
} | go | func NewMockisBatchRequest_Request_Request(ctrl *gomock.Controller) *MockisBatchRequest_Request_Request {
mock := &MockisBatchRequest_Request_Request{ctrl: ctrl}
mock.recorder = &MockisBatchRequest_Request_RequestMockRecorder{mock}
return mock
} | [
"func",
"NewMockisBatchRequest_Request_Request",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockisBatchRequest_Request_Request",
"{",
"mock",
":=",
"&",
"MockisBatchRequest_Request_Request",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockisBatchRequest_Request_RequestMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockisBatchRequest_Request_Request creates a new mock instance | [
"NewMockisBatchRequest_Request_Request",
"creates",
"a",
"new",
"mock",
"instance"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L26-L30 |
9,332 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | isBatchRequest_Request_Request | func (m *MockisBatchRequest_Request_Request) isBatchRequest_Request_Request() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "isBatchRequest_Request_Request")
} | go | func (m *MockisBatchRequest_Request_Request) isBatchRequest_Request_Request() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "isBatchRequest_Request_Request")
} | [
"func",
"(",
"m",
"*",
"MockisBatchRequest_Request_Request",
")",
"isBatchRequest_Request_Request",
"(",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // isBatchRequest_Request_Request mocks base method | [
"isBatchRequest_Request_Request",
"mocks",
"base",
"method"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L38-L41 |
9,333 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | isBatchRequest_Request_Request | func (mr *MockisBatchRequest_Request_RequestMockRecorder) isBatchRequest_Request_Request() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "isBatchRequest_Request_Request", reflect.TypeOf((*MockisBatchRequest_Request_Request)(nil).isBatchRequest_Request_Request))
} | go | func (mr *MockisBatchRequest_Request_RequestMockRecorder) isBatchRequest_Request_Request() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "isBatchRequest_Request_Request", reflect.TypeOf((*MockisBatchRequest_Request_Request)(nil).isBatchRequest_Request_Request))
} | [
"func",
"(",
"mr",
"*",
"MockisBatchRequest_Request_RequestMockRecorder",
")",
"isBatchRequest_Request_Request",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockisBatchRequest_Request_Request",
")",
"(",
"nil",
")",
".",
"isBatchRequest_Request_Request",
")",
")",
"\n",
"}"
] | // isBatchRequest_Request_Request indicates an expected call of isBatchRequest_Request_Request | [
"isBatchRequest_Request_Request",
"indicates",
"an",
"expected",
"call",
"of",
"isBatchRequest_Request_Request"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L44-L47 |
9,334 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | NewMockisBatchResponse_Response_Response | func NewMockisBatchResponse_Response_Response(ctrl *gomock.Controller) *MockisBatchResponse_Response_Response {
mock := &MockisBatchResponse_Response_Response{ctrl: ctrl}
mock.recorder = &MockisBatchResponse_Response_ResponseMockRecorder{mock}
return mock
} | go | func NewMockisBatchResponse_Response_Response(ctrl *gomock.Controller) *MockisBatchResponse_Response_Response {
mock := &MockisBatchResponse_Response_Response{ctrl: ctrl}
mock.recorder = &MockisBatchResponse_Response_ResponseMockRecorder{mock}
return mock
} | [
"func",
"NewMockisBatchResponse_Response_Response",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockisBatchResponse_Response_Response",
"{",
"mock",
":=",
"&",
"MockisBatchResponse_Response_Response",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockisBatchResponse_Response_ResponseMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockisBatchResponse_Response_Response creates a new mock instance | [
"NewMockisBatchResponse_Response_Response",
"creates",
"a",
"new",
"mock",
"instance"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L61-L65 |
9,335 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | isBatchResponse_Response_Response | func (m *MockisBatchResponse_Response_Response) isBatchResponse_Response_Response() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "isBatchResponse_Response_Response")
} | go | func (m *MockisBatchResponse_Response_Response) isBatchResponse_Response_Response() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "isBatchResponse_Response_Response")
} | [
"func",
"(",
"m",
"*",
"MockisBatchResponse_Response_Response",
")",
"isBatchResponse_Response_Response",
"(",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // isBatchResponse_Response_Response mocks base method | [
"isBatchResponse_Response_Response",
"mocks",
"base",
"method"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L73-L76 |
9,336 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | isBatchResponse_Response_Response | func (mr *MockisBatchResponse_Response_ResponseMockRecorder) isBatchResponse_Response_Response() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "isBatchResponse_Response_Response", reflect.TypeOf((*MockisBatchResponse_Response_Response)(nil).isBatchResponse_Response_Response))
} | go | func (mr *MockisBatchResponse_Response_ResponseMockRecorder) isBatchResponse_Response_Response() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "isBatchResponse_Response_Response", reflect.TypeOf((*MockisBatchResponse_Response_Response)(nil).isBatchResponse_Response_Response))
} | [
"func",
"(",
"mr",
"*",
"MockisBatchResponse_Response_ResponseMockRecorder",
")",
"isBatchResponse_Response_Response",
"(",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockisBatchResponse_Response_Response",
")",
"(",
"nil",
")",
".",
"isBatchResponse_Response_Response",
")",
")",
"\n",
"}"
] | // isBatchResponse_Response_Response indicates an expected call of isBatchResponse_Response_Response | [
"isBatchResponse_Response_Response",
"indicates",
"an",
"expected",
"call",
"of",
"isBatchResponse_Response_Response"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L79-L82 |
9,337 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | NewMockBuildsClient | func NewMockBuildsClient(ctrl *gomock.Controller) *MockBuildsClient {
mock := &MockBuildsClient{ctrl: ctrl}
mock.recorder = &MockBuildsClientMockRecorder{mock}
return mock
} | go | func NewMockBuildsClient(ctrl *gomock.Controller) *MockBuildsClient {
mock := &MockBuildsClient{ctrl: ctrl}
mock.recorder = &MockBuildsClientMockRecorder{mock}
return mock
} | [
"func",
"NewMockBuildsClient",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockBuildsClient",
"{",
"mock",
":=",
"&",
"MockBuildsClient",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockBuildsClientMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockBuildsClient creates a new mock instance | [
"NewMockBuildsClient",
"creates",
"a",
"new",
"mock",
"instance"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L96-L100 |
9,338 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | GetBuild | func (m *MockBuildsClient) GetBuild(ctx context.Context, in *GetBuildRequest, opts ...grpc.CallOption) (*Build, error) {
m.ctrl.T.Helper()
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetBuild", varargs...)
ret0, _ := ret[0].(*Build)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockBuildsClient) GetBuild(ctx context.Context, in *GetBuildRequest, opts ...grpc.CallOption) (*Build, error) {
m.ctrl.T.Helper()
varargs := []interface{}{ctx, in}
for _, a := range opts {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "GetBuild", varargs...)
ret0, _ := ret[0].(*Build)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockBuildsClient",
")",
"GetBuild",
"(",
"ctx",
"context",
".",
"Context",
",",
"in",
"*",
"GetBuildRequest",
",",
"opts",
"...",
"grpc",
".",
"CallOption",
")",
"(",
"*",
"Build",
",",
"error",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"varargs",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"ctx",
",",
"in",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"opts",
"{",
"varargs",
"=",
"append",
"(",
"varargs",
",",
"a",
")",
"\n",
"}",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"varargs",
"...",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"Build",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // GetBuild mocks base method | [
"GetBuild",
"mocks",
"base",
"method"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L108-L118 |
9,339 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | GetBuild | func (mr *MockBuildsClientMockRecorder) GetBuild(ctx, in interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBuild", reflect.TypeOf((*MockBuildsClient)(nil).GetBuild), varargs...)
} | go | func (mr *MockBuildsClientMockRecorder) GetBuild(ctx, in interface{}, opts ...interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
varargs := append([]interface{}{ctx, in}, opts...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBuild", reflect.TypeOf((*MockBuildsClient)(nil).GetBuild), varargs...)
} | [
"func",
"(",
"mr",
"*",
"MockBuildsClientMockRecorder",
")",
"GetBuild",
"(",
"ctx",
",",
"in",
"interface",
"{",
"}",
",",
"opts",
"...",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"varargs",
":=",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"ctx",
",",
"in",
"}",
",",
"opts",
"...",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockBuildsClient",
")",
"(",
"nil",
")",
".",
"GetBuild",
")",
",",
"varargs",
"...",
")",
"\n",
"}"
] | // GetBuild indicates an expected call of GetBuild | [
"GetBuild",
"indicates",
"an",
"expected",
"call",
"of",
"GetBuild"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L121-L125 |
9,340 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | NewMockBuildsServer | func NewMockBuildsServer(ctrl *gomock.Controller) *MockBuildsServer {
mock := &MockBuildsServer{ctrl: ctrl}
mock.recorder = &MockBuildsServerMockRecorder{mock}
return mock
} | go | func NewMockBuildsServer(ctrl *gomock.Controller) *MockBuildsServer {
mock := &MockBuildsServer{ctrl: ctrl}
mock.recorder = &MockBuildsServerMockRecorder{mock}
return mock
} | [
"func",
"NewMockBuildsServer",
"(",
"ctrl",
"*",
"gomock",
".",
"Controller",
")",
"*",
"MockBuildsServer",
"{",
"mock",
":=",
"&",
"MockBuildsServer",
"{",
"ctrl",
":",
"ctrl",
"}",
"\n",
"mock",
".",
"recorder",
"=",
"&",
"MockBuildsServerMockRecorder",
"{",
"mock",
"}",
"\n",
"return",
"mock",
"\n",
"}"
] | // NewMockBuildsServer creates a new mock instance | [
"NewMockBuildsServer",
"creates",
"a",
"new",
"mock",
"instance"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L239-L243 |
9,341 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | ScheduleBuild | func (m *MockBuildsServer) ScheduleBuild(arg0 context.Context, arg1 *ScheduleBuildRequest) (*Build, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ScheduleBuild", arg0, arg1)
ret0, _ := ret[0].(*Build)
ret1, _ := ret[1].(error)
return ret0, ret1
} | go | func (m *MockBuildsServer) ScheduleBuild(arg0 context.Context, arg1 *ScheduleBuildRequest) (*Build, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ScheduleBuild", arg0, arg1)
ret0, _ := ret[0].(*Build)
ret1, _ := ret[1].(error)
return ret0, ret1
} | [
"func",
"(",
"m",
"*",
"MockBuildsServer",
")",
"ScheduleBuild",
"(",
"arg0",
"context",
".",
"Context",
",",
"arg1",
"*",
"ScheduleBuildRequest",
")",
"(",
"*",
"Build",
",",
"error",
")",
"{",
"m",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"ret",
":=",
"m",
".",
"ctrl",
".",
"Call",
"(",
"m",
",",
"\"",
"\"",
",",
"arg0",
",",
"arg1",
")",
"\n",
"ret0",
",",
"_",
":=",
"ret",
"[",
"0",
"]",
".",
"(",
"*",
"Build",
")",
"\n",
"ret1",
",",
"_",
":=",
"ret",
"[",
"1",
"]",
".",
"(",
"error",
")",
"\n",
"return",
"ret0",
",",
"ret1",
"\n",
"}"
] | // ScheduleBuild mocks base method | [
"ScheduleBuild",
"mocks",
"base",
"method"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L296-L302 |
9,342 | luci/luci-go | buildbucket/proto/rpc.mock.pb.go | ScheduleBuild | func (mr *MockBuildsServerMockRecorder) ScheduleBuild(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduleBuild", reflect.TypeOf((*MockBuildsServer)(nil).ScheduleBuild), arg0, arg1)
} | go | func (mr *MockBuildsServerMockRecorder) ScheduleBuild(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduleBuild", reflect.TypeOf((*MockBuildsServer)(nil).ScheduleBuild), arg0, arg1)
} | [
"func",
"(",
"mr",
"*",
"MockBuildsServerMockRecorder",
")",
"ScheduleBuild",
"(",
"arg0",
",",
"arg1",
"interface",
"{",
"}",
")",
"*",
"gomock",
".",
"Call",
"{",
"mr",
".",
"mock",
".",
"ctrl",
".",
"T",
".",
"Helper",
"(",
")",
"\n",
"return",
"mr",
".",
"mock",
".",
"ctrl",
".",
"RecordCallWithMethodType",
"(",
"mr",
".",
"mock",
",",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"MockBuildsServer",
")",
"(",
"nil",
")",
".",
"ScheduleBuild",
")",
",",
"arg0",
",",
"arg1",
")",
"\n",
"}"
] | // ScheduleBuild indicates an expected call of ScheduleBuild | [
"ScheduleBuild",
"indicates",
"an",
"expected",
"call",
"of",
"ScheduleBuild"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/proto/rpc.mock.pb.go#L305-L308 |
9,343 | luci/luci-go | lucicfg/cli/base/base.go | NewCLIError | func NewCLIError(msg string, args ...interface{}) error {
return CommandLineError{fmt.Errorf(msg, args...)}
} | go | func NewCLIError(msg string, args ...interface{}) error {
return CommandLineError{fmt.Errorf(msg, args...)}
} | [
"func",
"NewCLIError",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"CommandLineError",
"{",
"fmt",
".",
"Errorf",
"(",
"msg",
",",
"args",
"...",
")",
"}",
"\n",
"}"
] | // NewCLIError returns new CommandLineError. | [
"NewCLIError",
"returns",
"new",
"CommandLineError",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/lucicfg/cli/base/base.go#L46-L48 |
9,344 | luci/luci-go | lucicfg/cli/base/base.go | Init | func (c *Subcommand) Init(params Parameters) {
c.params = ¶ms
c.Meta = c.DefaultMeta()
c.logConfig.Level = logging.Info
c.logConfig.AddFlags(&c.Flags)
c.authFlags.Register(&c.Flags, params.AuthOptions)
c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write operation results to.")
} | go | func (c *Subcommand) Init(params Parameters) {
c.params = ¶ms
c.Meta = c.DefaultMeta()
c.logConfig.Level = logging.Info
c.logConfig.AddFlags(&c.Flags)
c.authFlags.Register(&c.Flags, params.AuthOptions)
c.Flags.StringVar(&c.jsonOutput, "json-output", "", "Path to write operation results to.")
} | [
"func",
"(",
"c",
"*",
"Subcommand",
")",
"Init",
"(",
"params",
"Parameters",
")",
"{",
"c",
".",
"params",
"=",
"&",
"params",
"\n",
"c",
".",
"Meta",
"=",
"c",
".",
"DefaultMeta",
"(",
")",
"\n",
"c",
".",
"logConfig",
".",
"Level",
"=",
"logging",
".",
"Info",
"\n\n",
"c",
".",
"logConfig",
".",
"AddFlags",
"(",
"&",
"c",
".",
"Flags",
")",
"\n",
"c",
".",
"authFlags",
".",
"Register",
"(",
"&",
"c",
".",
"Flags",
",",
"params",
".",
"AuthOptions",
")",
"\n",
"c",
".",
"Flags",
".",
"StringVar",
"(",
"&",
"c",
".",
"jsonOutput",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Init registers common flags. | [
"Init",
"registers",
"common",
"flags",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/lucicfg/cli/base/base.go#L85-L93 |
9,345 | luci/luci-go | lucicfg/cli/base/base.go | AddMetaFlags | func (c *Subcommand) AddMetaFlags() {
if c.params == nil {
panic("call Init first")
}
c.Meta.AddFlags(&c.Flags)
} | go | func (c *Subcommand) AddMetaFlags() {
if c.params == nil {
panic("call Init first")
}
c.Meta.AddFlags(&c.Flags)
} | [
"func",
"(",
"c",
"*",
"Subcommand",
")",
"AddMetaFlags",
"(",
")",
"{",
"if",
"c",
".",
"params",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"Meta",
".",
"AddFlags",
"(",
"&",
"c",
".",
"Flags",
")",
"\n",
"}"
] | // AddMetaFlags registers c.Meta in the FlagSet.
//
// Used by subcommands that end up executing Starlark. | [
"AddMetaFlags",
"registers",
"c",
".",
"Meta",
"in",
"the",
"FlagSet",
".",
"Used",
"by",
"subcommands",
"that",
"end",
"up",
"executing",
"Starlark",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/lucicfg/cli/base/base.go#L110-L115 |
9,346 | luci/luci-go | lucicfg/cli/base/base.go | printError | func (c *Subcommand) printError(err error) {
if _, ok := err.(CommandLineError); ok {
fmt.Fprintf(os.Stderr, "Bad command line: %s.\n\n", err)
c.Flags.Usage()
} else {
os.Stderr.WriteString(strings.Join(CollectErrorMessages(err, nil), "\n"))
os.Stderr.WriteString("\n")
}
} | go | func (c *Subcommand) printError(err error) {
if _, ok := err.(CommandLineError); ok {
fmt.Fprintf(os.Stderr, "Bad command line: %s.\n\n", err)
c.Flags.Usage()
} else {
os.Stderr.WriteString(strings.Join(CollectErrorMessages(err, nil), "\n"))
os.Stderr.WriteString("\n")
}
} | [
"func",
"(",
"c",
"*",
"Subcommand",
")",
"printError",
"(",
"err",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"CommandLineError",
")",
";",
"ok",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"err",
")",
"\n",
"c",
".",
"Flags",
".",
"Usage",
"(",
")",
"\n",
"}",
"else",
"{",
"os",
".",
"Stderr",
".",
"WriteString",
"(",
"strings",
".",
"Join",
"(",
"CollectErrorMessages",
"(",
"err",
",",
"nil",
")",
",",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"os",
".",
"Stderr",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // printError prints an error to stderr.
//
// Recognizes various sorts of known errors and reports the appropriately. | [
"printError",
"prints",
"an",
"error",
"to",
"stderr",
".",
"Recognizes",
"various",
"sorts",
"of",
"known",
"errors",
"and",
"reports",
"the",
"appropriately",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/lucicfg/cli/base/base.go#L206-L214 |
9,347 | luci/luci-go | milo/buildsource/buildbot/buildstore/annotations.go | fetchAnnotationProto | func fetchAnnotationProto(c context.Context, addr *types.StreamAddr) (*miloProto.Step, error) {
// The implementation avoids using existing Milo code because the latter is
// likely to change and because it does things that we don't need here e.g.
// caching that wouldn't apply anyway, etc.
// Instead we use LogDog client directly, and thus make it simpler to
// reason what this function actually does.
// This is not performance critical code.
// Create a LogDog client.
transport, err := auth.GetRPCTransport(c, auth.AsUser)
if err != nil {
return nil, errors.New("failed to get transport for LogDog server")
}
client := coordinator.NewClient(&prpc.Client{
C: &http.Client{Transport: transport},
Host: addr.Host,
})
// Load the last datagram.
var state coordinator.LogStream
logEntry, err := client.Stream(addr.Project, addr.Path).
Tail(c, coordinator.WithState(&state), coordinator.Complete())
switch {
case err == coordinator.ErrNoSuchStream:
return nil, errAnnotationNotFound
case err == coordinator.ErrNoAccess:
// Tag with Milo internal tags.
return nil, errors.Annotate(err, "getting logdog stream").Tag(grpcutil.PermissionDeniedTag).Err()
case err != nil:
return nil, err
case state.Desc.StreamType != logpb.StreamType_DATAGRAM:
return nil, errors.New("not a datagram stream")
case logEntry == nil:
return nil, errAnnotationNotFound
}
// Decode the datagram as an annotation proto.
var res miloProto.Step
if err := proto.Unmarshal(logEntry.GetDatagram().Data, &res); err != nil {
return nil, err
}
return &res, nil
} | go | func fetchAnnotationProto(c context.Context, addr *types.StreamAddr) (*miloProto.Step, error) {
// The implementation avoids using existing Milo code because the latter is
// likely to change and because it does things that we don't need here e.g.
// caching that wouldn't apply anyway, etc.
// Instead we use LogDog client directly, and thus make it simpler to
// reason what this function actually does.
// This is not performance critical code.
// Create a LogDog client.
transport, err := auth.GetRPCTransport(c, auth.AsUser)
if err != nil {
return nil, errors.New("failed to get transport for LogDog server")
}
client := coordinator.NewClient(&prpc.Client{
C: &http.Client{Transport: transport},
Host: addr.Host,
})
// Load the last datagram.
var state coordinator.LogStream
logEntry, err := client.Stream(addr.Project, addr.Path).
Tail(c, coordinator.WithState(&state), coordinator.Complete())
switch {
case err == coordinator.ErrNoSuchStream:
return nil, errAnnotationNotFound
case err == coordinator.ErrNoAccess:
// Tag with Milo internal tags.
return nil, errors.Annotate(err, "getting logdog stream").Tag(grpcutil.PermissionDeniedTag).Err()
case err != nil:
return nil, err
case state.Desc.StreamType != logpb.StreamType_DATAGRAM:
return nil, errors.New("not a datagram stream")
case logEntry == nil:
return nil, errAnnotationNotFound
}
// Decode the datagram as an annotation proto.
var res miloProto.Step
if err := proto.Unmarshal(logEntry.GetDatagram().Data, &res); err != nil {
return nil, err
}
return &res, nil
} | [
"func",
"fetchAnnotationProto",
"(",
"c",
"context",
".",
"Context",
",",
"addr",
"*",
"types",
".",
"StreamAddr",
")",
"(",
"*",
"miloProto",
".",
"Step",
",",
"error",
")",
"{",
"// The implementation avoids using existing Milo code because the latter is",
"// likely to change and because it does things that we don't need here e.g.",
"// caching that wouldn't apply anyway, etc.",
"// Instead we use LogDog client directly, and thus make it simpler to",
"// reason what this function actually does.",
"// This is not performance critical code.",
"// Create a LogDog client.",
"transport",
",",
"err",
":=",
"auth",
".",
"GetRPCTransport",
"(",
"c",
",",
"auth",
".",
"AsUser",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"client",
":=",
"coordinator",
".",
"NewClient",
"(",
"&",
"prpc",
".",
"Client",
"{",
"C",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"transport",
"}",
",",
"Host",
":",
"addr",
".",
"Host",
",",
"}",
")",
"\n\n",
"// Load the last datagram.",
"var",
"state",
"coordinator",
".",
"LogStream",
"\n",
"logEntry",
",",
"err",
":=",
"client",
".",
"Stream",
"(",
"addr",
".",
"Project",
",",
"addr",
".",
"Path",
")",
".",
"Tail",
"(",
"c",
",",
"coordinator",
".",
"WithState",
"(",
"&",
"state",
")",
",",
"coordinator",
".",
"Complete",
"(",
")",
")",
"\n",
"switch",
"{",
"case",
"err",
"==",
"coordinator",
".",
"ErrNoSuchStream",
":",
"return",
"nil",
",",
"errAnnotationNotFound",
"\n",
"case",
"err",
"==",
"coordinator",
".",
"ErrNoAccess",
":",
"// Tag with Milo internal tags.",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Tag",
"(",
"grpcutil",
".",
"PermissionDeniedTag",
")",
".",
"Err",
"(",
")",
"\n",
"case",
"err",
"!=",
"nil",
":",
"return",
"nil",
",",
"err",
"\n",
"case",
"state",
".",
"Desc",
".",
"StreamType",
"!=",
"logpb",
".",
"StreamType_DATAGRAM",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"logEntry",
"==",
"nil",
":",
"return",
"nil",
",",
"errAnnotationNotFound",
"\n",
"}",
"\n\n",
"// Decode the datagram as an annotation proto.",
"var",
"res",
"miloProto",
".",
"Step",
"\n",
"if",
"err",
":=",
"proto",
".",
"Unmarshal",
"(",
"logEntry",
".",
"GetDatagram",
"(",
")",
".",
"Data",
",",
"&",
"res",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"res",
",",
"nil",
"\n",
"}"
] | // fetchAnnotationProto fetches an annotation proto from LogDog.
// If the stream is not found, returns errAnnotationNotFound. | [
"fetchAnnotationProto",
"fetches",
"an",
"annotation",
"proto",
"from",
"LogDog",
".",
"If",
"the",
"stream",
"is",
"not",
"found",
"returns",
"errAnnotationNotFound",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/buildsource/buildbot/buildstore/annotations.go#L51-L93 |
9,348 | luci/luci-go | milo/buildsource/buildbot/buildstore/annotations.go | addSteps | func (ac *annotationConverter) addSteps(c context.Context, dest *[]buildbot.Step, src []*miloProto.Step_Substep, stepNamePrefix string) error {
for _, substep := range src {
stepSrc := substep.GetStep()
if stepSrc == nil {
return errors.Reason("unexpected substep type %T", substep.Substep).Err()
}
stepDst, err := ac.step(c, stepSrc)
if err != nil {
return errors.Annotate(err, "could not convert step %q", stepNamePrefix+stepDst.Name).Err()
}
stepDst.Name = stepNamePrefix + stepDst.Name
*dest = append(*dest, *stepDst)
ac.addSteps(c, dest, stepSrc.Substep, stepDst.Name+".")
}
return nil
} | go | func (ac *annotationConverter) addSteps(c context.Context, dest *[]buildbot.Step, src []*miloProto.Step_Substep, stepNamePrefix string) error {
for _, substep := range src {
stepSrc := substep.GetStep()
if stepSrc == nil {
return errors.Reason("unexpected substep type %T", substep.Substep).Err()
}
stepDst, err := ac.step(c, stepSrc)
if err != nil {
return errors.Annotate(err, "could not convert step %q", stepNamePrefix+stepDst.Name).Err()
}
stepDst.Name = stepNamePrefix + stepDst.Name
*dest = append(*dest, *stepDst)
ac.addSteps(c, dest, stepSrc.Substep, stepDst.Name+".")
}
return nil
} | [
"func",
"(",
"ac",
"*",
"annotationConverter",
")",
"addSteps",
"(",
"c",
"context",
".",
"Context",
",",
"dest",
"*",
"[",
"]",
"buildbot",
".",
"Step",
",",
"src",
"[",
"]",
"*",
"miloProto",
".",
"Step_Substep",
",",
"stepNamePrefix",
"string",
")",
"error",
"{",
"for",
"_",
",",
"substep",
":=",
"range",
"src",
"{",
"stepSrc",
":=",
"substep",
".",
"GetStep",
"(",
")",
"\n",
"if",
"stepSrc",
"==",
"nil",
"{",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
",",
"substep",
".",
"Substep",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n\n",
"stepDst",
",",
"err",
":=",
"ac",
".",
"step",
"(",
"c",
",",
"stepSrc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"stepNamePrefix",
"+",
"stepDst",
".",
"Name",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"stepDst",
".",
"Name",
"=",
"stepNamePrefix",
"+",
"stepDst",
".",
"Name",
"\n",
"*",
"dest",
"=",
"append",
"(",
"*",
"dest",
",",
"*",
"stepDst",
")",
"\n",
"ac",
".",
"addSteps",
"(",
"c",
",",
"dest",
",",
"stepSrc",
".",
"Substep",
",",
"stepDst",
".",
"Name",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // addSteps converts annotation substeps to buildbot steps and appends them
// dest.
// c is used only for logging. | [
"addSteps",
"converts",
"annotation",
"substeps",
"to",
"buildbot",
"steps",
"and",
"appends",
"them",
"dest",
".",
"c",
"is",
"used",
"only",
"for",
"logging",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/buildsource/buildbot/buildstore/annotations.go#L104-L120 |
9,349 | luci/luci-go | milo/buildsource/buildbot/buildstore/annotations.go | step | func (ac *annotationConverter) step(c context.Context, src *miloProto.Step) (*buildbot.Step, error) {
// This implementation is based on
// https://chromium.googlesource.com/infra/luci/luci-go/+/7ad046489c578e339b873886d6973abbe43cc137/milo/buildsource/rawpresentation/logDogBuild.go#47
res := &buildbot.Step{
Name: src.Name,
IsStarted: true,
IsFinished: src.Ended != nil,
}
// Convert step result.
switch {
case src.Status == miloProto.Status_SUCCESS:
res.Results.Result = buildbot.Success
case src.Status == miloProto.Status_FAILURE:
res.Results.Result = buildbot.Failure
if fd := src.GetFailureDetails(); fd != nil {
if fd.Type != miloProto.FailureDetails_GENERAL {
res.Results.Result = buildbot.Exception
}
if fd.Text != "" {
res.Text = append(res.Text, fd.Text)
}
}
case !ac.buildCompletedTime.IsZero():
res.Results.Result = buildbot.Exception
default:
res.Results.Result = buildbot.NoResult
}
// annotee never initializes src.Link
var allLinks []*miloProto.Link
if src.StdoutStream != nil {
allLinks = append(allLinks, &miloProto.Link{
Label: "stdout",
Value: &miloProto.Link_LogdogStream{src.StdoutStream},
})
}
if src.StderrStream != nil {
allLinks = append(allLinks, &miloProto.Link{
Label: "stderr",
Value: &miloProto.Link_LogdogStream{src.StdoutStream},
})
}
allLinks = append(allLinks, src.OtherLinks...)
for _, l := range allLinks {
log, err := ac.log(l)
if err != nil {
logging.WithError(err).Errorf(c, "could not convert link %q to buildbot", l.Label)
continue
}
res.Logs = append(res.Logs, *log)
}
// Timestamps
if src.Started != nil {
var err error
res.Times.Start.Time, err = ptypes.Timestamp(src.Started)
if err != nil {
return nil, errors.Annotate(err, "invalid start time").Err()
}
if src.Ended != nil {
res.Times.Finish.Time, err = ptypes.Timestamp(src.Ended)
if err != nil {
return nil, errors.Annotate(err, "invalid end time").Err()
}
} else {
res.Times.Finish.Time = ac.buildCompletedTime
}
}
for _, line := range src.Text {
// src.Text may contain <br> ;(
res.Text = append(res.Text, reLineBreak.Split(line, -1)...)
}
return res, nil
} | go | func (ac *annotationConverter) step(c context.Context, src *miloProto.Step) (*buildbot.Step, error) {
// This implementation is based on
// https://chromium.googlesource.com/infra/luci/luci-go/+/7ad046489c578e339b873886d6973abbe43cc137/milo/buildsource/rawpresentation/logDogBuild.go#47
res := &buildbot.Step{
Name: src.Name,
IsStarted: true,
IsFinished: src.Ended != nil,
}
// Convert step result.
switch {
case src.Status == miloProto.Status_SUCCESS:
res.Results.Result = buildbot.Success
case src.Status == miloProto.Status_FAILURE:
res.Results.Result = buildbot.Failure
if fd := src.GetFailureDetails(); fd != nil {
if fd.Type != miloProto.FailureDetails_GENERAL {
res.Results.Result = buildbot.Exception
}
if fd.Text != "" {
res.Text = append(res.Text, fd.Text)
}
}
case !ac.buildCompletedTime.IsZero():
res.Results.Result = buildbot.Exception
default:
res.Results.Result = buildbot.NoResult
}
// annotee never initializes src.Link
var allLinks []*miloProto.Link
if src.StdoutStream != nil {
allLinks = append(allLinks, &miloProto.Link{
Label: "stdout",
Value: &miloProto.Link_LogdogStream{src.StdoutStream},
})
}
if src.StderrStream != nil {
allLinks = append(allLinks, &miloProto.Link{
Label: "stderr",
Value: &miloProto.Link_LogdogStream{src.StdoutStream},
})
}
allLinks = append(allLinks, src.OtherLinks...)
for _, l := range allLinks {
log, err := ac.log(l)
if err != nil {
logging.WithError(err).Errorf(c, "could not convert link %q to buildbot", l.Label)
continue
}
res.Logs = append(res.Logs, *log)
}
// Timestamps
if src.Started != nil {
var err error
res.Times.Start.Time, err = ptypes.Timestamp(src.Started)
if err != nil {
return nil, errors.Annotate(err, "invalid start time").Err()
}
if src.Ended != nil {
res.Times.Finish.Time, err = ptypes.Timestamp(src.Ended)
if err != nil {
return nil, errors.Annotate(err, "invalid end time").Err()
}
} else {
res.Times.Finish.Time = ac.buildCompletedTime
}
}
for _, line := range src.Text {
// src.Text may contain <br> ;(
res.Text = append(res.Text, reLineBreak.Split(line, -1)...)
}
return res, nil
} | [
"func",
"(",
"ac",
"*",
"annotationConverter",
")",
"step",
"(",
"c",
"context",
".",
"Context",
",",
"src",
"*",
"miloProto",
".",
"Step",
")",
"(",
"*",
"buildbot",
".",
"Step",
",",
"error",
")",
"{",
"// This implementation is based on",
"// https://chromium.googlesource.com/infra/luci/luci-go/+/7ad046489c578e339b873886d6973abbe43cc137/milo/buildsource/rawpresentation/logDogBuild.go#47",
"res",
":=",
"&",
"buildbot",
".",
"Step",
"{",
"Name",
":",
"src",
".",
"Name",
",",
"IsStarted",
":",
"true",
",",
"IsFinished",
":",
"src",
".",
"Ended",
"!=",
"nil",
",",
"}",
"\n\n",
"// Convert step result.",
"switch",
"{",
"case",
"src",
".",
"Status",
"==",
"miloProto",
".",
"Status_SUCCESS",
":",
"res",
".",
"Results",
".",
"Result",
"=",
"buildbot",
".",
"Success",
"\n\n",
"case",
"src",
".",
"Status",
"==",
"miloProto",
".",
"Status_FAILURE",
":",
"res",
".",
"Results",
".",
"Result",
"=",
"buildbot",
".",
"Failure",
"\n",
"if",
"fd",
":=",
"src",
".",
"GetFailureDetails",
"(",
")",
";",
"fd",
"!=",
"nil",
"{",
"if",
"fd",
".",
"Type",
"!=",
"miloProto",
".",
"FailureDetails_GENERAL",
"{",
"res",
".",
"Results",
".",
"Result",
"=",
"buildbot",
".",
"Exception",
"\n",
"}",
"\n",
"if",
"fd",
".",
"Text",
"!=",
"\"",
"\"",
"{",
"res",
".",
"Text",
"=",
"append",
"(",
"res",
".",
"Text",
",",
"fd",
".",
"Text",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"!",
"ac",
".",
"buildCompletedTime",
".",
"IsZero",
"(",
")",
":",
"res",
".",
"Results",
".",
"Result",
"=",
"buildbot",
".",
"Exception",
"\n\n",
"default",
":",
"res",
".",
"Results",
".",
"Result",
"=",
"buildbot",
".",
"NoResult",
"\n",
"}",
"\n\n",
"// annotee never initializes src.Link",
"var",
"allLinks",
"[",
"]",
"*",
"miloProto",
".",
"Link",
"\n",
"if",
"src",
".",
"StdoutStream",
"!=",
"nil",
"{",
"allLinks",
"=",
"append",
"(",
"allLinks",
",",
"&",
"miloProto",
".",
"Link",
"{",
"Label",
":",
"\"",
"\"",
",",
"Value",
":",
"&",
"miloProto",
".",
"Link_LogdogStream",
"{",
"src",
".",
"StdoutStream",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"src",
".",
"StderrStream",
"!=",
"nil",
"{",
"allLinks",
"=",
"append",
"(",
"allLinks",
",",
"&",
"miloProto",
".",
"Link",
"{",
"Label",
":",
"\"",
"\"",
",",
"Value",
":",
"&",
"miloProto",
".",
"Link_LogdogStream",
"{",
"src",
".",
"StdoutStream",
"}",
",",
"}",
")",
"\n",
"}",
"\n",
"allLinks",
"=",
"append",
"(",
"allLinks",
",",
"src",
".",
"OtherLinks",
"...",
")",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"allLinks",
"{",
"log",
",",
"err",
":=",
"ac",
".",
"log",
"(",
"l",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logging",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"c",
",",
"\"",
"\"",
",",
"l",
".",
"Label",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"res",
".",
"Logs",
"=",
"append",
"(",
"res",
".",
"Logs",
",",
"*",
"log",
")",
"\n",
"}",
"\n\n",
"// Timestamps",
"if",
"src",
".",
"Started",
"!=",
"nil",
"{",
"var",
"err",
"error",
"\n",
"res",
".",
"Times",
".",
"Start",
".",
"Time",
",",
"err",
"=",
"ptypes",
".",
"Timestamp",
"(",
"src",
".",
"Started",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"if",
"src",
".",
"Ended",
"!=",
"nil",
"{",
"res",
".",
"Times",
".",
"Finish",
".",
"Time",
",",
"err",
"=",
"ptypes",
".",
"Timestamp",
"(",
"src",
".",
"Ended",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"res",
".",
"Times",
".",
"Finish",
".",
"Time",
"=",
"ac",
".",
"buildCompletedTime",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"line",
":=",
"range",
"src",
".",
"Text",
"{",
"// src.Text may contain <br> ;(",
"res",
".",
"Text",
"=",
"append",
"(",
"res",
".",
"Text",
",",
"reLineBreak",
".",
"Split",
"(",
"line",
",",
"-",
"1",
")",
"...",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // step converts an annotation step to a buildbot step. | [
"step",
"converts",
"an",
"annotation",
"step",
"to",
"a",
"buildbot",
"step",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/buildsource/buildbot/buildstore/annotations.go#L123-L202 |
9,350 | luci/luci-go | buildbucket/cli/app.go | application | func application(p Params) *cli.Application {
p.Auth.Scopes = []string{
auth.OAuthScopeEmail,
gerrit.OAuthScope,
}
return &cli.Application{
Name: "bb",
Title: "A CLI client for buildbucket.",
Context: func(ctx context.Context) context.Context {
return logCfg.Use(ctx)
},
Commands: []*subcommands.Command{
cmdAdd(p),
cmdGet(p),
cmdLS(p),
cmdLog(p),
cmdCancel(p),
cmdBatch(p),
cmdCollect(p),
{},
authcli.SubcommandLogin(p.Auth, "auth-login", false),
authcli.SubcommandLogout(p.Auth, "auth-logout", false),
authcli.SubcommandInfo(p.Auth, "auth-info", false),
{},
subcommands.CmdHelp,
},
}
} | go | func application(p Params) *cli.Application {
p.Auth.Scopes = []string{
auth.OAuthScopeEmail,
gerrit.OAuthScope,
}
return &cli.Application{
Name: "bb",
Title: "A CLI client for buildbucket.",
Context: func(ctx context.Context) context.Context {
return logCfg.Use(ctx)
},
Commands: []*subcommands.Command{
cmdAdd(p),
cmdGet(p),
cmdLS(p),
cmdLog(p),
cmdCancel(p),
cmdBatch(p),
cmdCollect(p),
{},
authcli.SubcommandLogin(p.Auth, "auth-login", false),
authcli.SubcommandLogout(p.Auth, "auth-logout", false),
authcli.SubcommandInfo(p.Auth, "auth-info", false),
{},
subcommands.CmdHelp,
},
}
} | [
"func",
"application",
"(",
"p",
"Params",
")",
"*",
"cli",
".",
"Application",
"{",
"p",
".",
"Auth",
".",
"Scopes",
"=",
"[",
"]",
"string",
"{",
"auth",
".",
"OAuthScopeEmail",
",",
"gerrit",
".",
"OAuthScope",
",",
"}",
"\n\n",
"return",
"&",
"cli",
".",
"Application",
"{",
"Name",
":",
"\"",
"\"",
",",
"Title",
":",
"\"",
"\"",
",",
"Context",
":",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"context",
".",
"Context",
"{",
"return",
"logCfg",
".",
"Use",
"(",
"ctx",
")",
"\n",
"}",
",",
"Commands",
":",
"[",
"]",
"*",
"subcommands",
".",
"Command",
"{",
"cmdAdd",
"(",
"p",
")",
",",
"cmdGet",
"(",
"p",
")",
",",
"cmdLS",
"(",
"p",
")",
",",
"cmdLog",
"(",
"p",
")",
",",
"cmdCancel",
"(",
"p",
")",
",",
"cmdBatch",
"(",
"p",
")",
",",
"cmdCollect",
"(",
"p",
")",
",",
"{",
"}",
",",
"authcli",
".",
"SubcommandLogin",
"(",
"p",
".",
"Auth",
",",
"\"",
"\"",
",",
"false",
")",
",",
"authcli",
".",
"SubcommandLogout",
"(",
"p",
".",
"Auth",
",",
"\"",
"\"",
",",
"false",
")",
",",
"authcli",
".",
"SubcommandInfo",
"(",
"p",
".",
"Auth",
",",
"\"",
"\"",
",",
"false",
")",
",",
"{",
"}",
",",
"subcommands",
".",
"CmdHelp",
",",
"}",
",",
"}",
"\n",
"}"
] | // application creates the application and configures its subcommands.
// Ignores p.Auth.Scopes. | [
"application",
"creates",
"the",
"application",
"and",
"configures",
"its",
"subcommands",
".",
"Ignores",
"p",
".",
"Auth",
".",
"Scopes",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/buildbucket/cli/app.go#L43-L73 |
9,351 | luci/luci-go | common/data/caching/cache/lru.go | keys | func (o *orderedDict) keys() isolated.HexDigests {
out := make(isolated.HexDigests, 0, o.length())
for e := o.ll.Front(); e != nil; e = e.Next() {
out = append(out, e.Value.(*entry).key)
}
return out
} | go | func (o *orderedDict) keys() isolated.HexDigests {
out := make(isolated.HexDigests, 0, o.length())
for e := o.ll.Front(); e != nil; e = e.Next() {
out = append(out, e.Value.(*entry).key)
}
return out
} | [
"func",
"(",
"o",
"*",
"orderedDict",
")",
"keys",
"(",
")",
"isolated",
".",
"HexDigests",
"{",
"out",
":=",
"make",
"(",
"isolated",
".",
"HexDigests",
",",
"0",
",",
"o",
".",
"length",
"(",
")",
")",
"\n",
"for",
"e",
":=",
"o",
".",
"ll",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"e",
".",
"Value",
".",
"(",
"*",
"entry",
")",
".",
"key",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // keys returns the keys in order. | [
"keys",
"returns",
"the",
"keys",
"in",
"order",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/data/caching/cache/lru.go#L75-L81 |
9,352 | luci/luci-go | common/data/caching/cache/lru.go | serialized | func (o *orderedDict) serialized() []entry {
out := make([]entry, 0, o.length())
for e := o.ll.Front(); e != nil; e = e.Next() {
out = append(out, *e.Value.(*entry))
}
return out
} | go | func (o *orderedDict) serialized() []entry {
out := make([]entry, 0, o.length())
for e := o.ll.Front(); e != nil; e = e.Next() {
out = append(out, *e.Value.(*entry))
}
return out
} | [
"func",
"(",
"o",
"*",
"orderedDict",
")",
"serialized",
"(",
")",
"[",
"]",
"entry",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"entry",
",",
"0",
",",
"o",
".",
"length",
"(",
")",
")",
"\n",
"for",
"e",
":=",
"o",
".",
"ll",
".",
"Front",
"(",
")",
";",
"e",
"!=",
"nil",
";",
"e",
"=",
"e",
".",
"Next",
"(",
")",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"*",
"e",
".",
"Value",
".",
"(",
"*",
"entry",
")",
")",
"\n",
"}",
"\n",
"return",
"out",
"\n",
"}"
] | // serialized returns all the items in order. | [
"serialized",
"returns",
"all",
"the",
"items",
"in",
"order",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/data/caching/cache/lru.go#L128-L134 |
9,353 | luci/luci-go | cipd/appengine/ui/nav.go | breadcrumbs | func breadcrumbs(path string, ver string) []breadcrumb {
out := []breadcrumb{
{Title: "[root]", Href: prefixPageURL("")},
}
if path != "" {
chunks := strings.Split(path, "/")
for i, ch := range chunks {
out = append(out, breadcrumb{
Title: ch,
Href: prefixPageURL(strings.Join(chunks[:i+1], "/")),
})
}
}
// This is a breadcrumb path to an instance of package named 'path'. Fix URL
// of the crumb that corresponds to the package to point to the package page,
// not the prefix page.
if ver != "" {
out[len(out)-1].Href = packagePageURL(path, "")
out = append(out, breadcrumb{
Title: ver,
Href: instancePageURL(path, ver),
})
}
out[len(out)-1].Last = true
return out
} | go | func breadcrumbs(path string, ver string) []breadcrumb {
out := []breadcrumb{
{Title: "[root]", Href: prefixPageURL("")},
}
if path != "" {
chunks := strings.Split(path, "/")
for i, ch := range chunks {
out = append(out, breadcrumb{
Title: ch,
Href: prefixPageURL(strings.Join(chunks[:i+1], "/")),
})
}
}
// This is a breadcrumb path to an instance of package named 'path'. Fix URL
// of the crumb that corresponds to the package to point to the package page,
// not the prefix page.
if ver != "" {
out[len(out)-1].Href = packagePageURL(path, "")
out = append(out, breadcrumb{
Title: ver,
Href: instancePageURL(path, ver),
})
}
out[len(out)-1].Last = true
return out
} | [
"func",
"breadcrumbs",
"(",
"path",
"string",
",",
"ver",
"string",
")",
"[",
"]",
"breadcrumb",
"{",
"out",
":=",
"[",
"]",
"breadcrumb",
"{",
"{",
"Title",
":",
"\"",
"\"",
",",
"Href",
":",
"prefixPageURL",
"(",
"\"",
"\"",
")",
"}",
",",
"}",
"\n",
"if",
"path",
"!=",
"\"",
"\"",
"{",
"chunks",
":=",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"\n",
"for",
"i",
",",
"ch",
":=",
"range",
"chunks",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"breadcrumb",
"{",
"Title",
":",
"ch",
",",
"Href",
":",
"prefixPageURL",
"(",
"strings",
".",
"Join",
"(",
"chunks",
"[",
":",
"i",
"+",
"1",
"]",
",",
"\"",
"\"",
")",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// This is a breadcrumb path to an instance of package named 'path'. Fix URL",
"// of the crumb that corresponds to the package to point to the package page,",
"// not the prefix page.",
"if",
"ver",
"!=",
"\"",
"\"",
"{",
"out",
"[",
"len",
"(",
"out",
")",
"-",
"1",
"]",
".",
"Href",
"=",
"packagePageURL",
"(",
"path",
",",
"\"",
"\"",
")",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"breadcrumb",
"{",
"Title",
":",
"ver",
",",
"Href",
":",
"instancePageURL",
"(",
"path",
",",
"ver",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"out",
"[",
"len",
"(",
"out",
")",
"-",
"1",
"]",
".",
"Last",
"=",
"true",
"\n",
"return",
"out",
"\n",
"}"
] | // breadcrumbs builds a data for the breadcrumps navigation element.
//
// It contains a prefix path, where each element is clickable. | [
"breadcrumbs",
"builds",
"a",
"data",
"for",
"the",
"breadcrumps",
"navigation",
"element",
".",
"It",
"contains",
"a",
"prefix",
"path",
"where",
"each",
"element",
"is",
"clickable",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/appengine/ui/nav.go#L30-L57 |
9,354 | luci/luci-go | cipd/appengine/ui/nav.go | prefixesListing | func prefixesListing(pfx string, prefixes []string) []listingItem {
out := make([]listingItem, 0, len(prefixes)+1)
if pfx != "" {
parent := ""
if idx := strings.LastIndex(pfx, "/"); idx != -1 {
parent = pfx[:idx]
}
out = append(out, listingItem{
Back: true,
Href: prefixPageURL(parent),
})
}
return pathListing(pfx, prefixes, out, func(p string) listingItem {
return listingItem{
Href: prefixPageURL(p),
}
})
} | go | func prefixesListing(pfx string, prefixes []string) []listingItem {
out := make([]listingItem, 0, len(prefixes)+1)
if pfx != "" {
parent := ""
if idx := strings.LastIndex(pfx, "/"); idx != -1 {
parent = pfx[:idx]
}
out = append(out, listingItem{
Back: true,
Href: prefixPageURL(parent),
})
}
return pathListing(pfx, prefixes, out, func(p string) listingItem {
return listingItem{
Href: prefixPageURL(p),
}
})
} | [
"func",
"prefixesListing",
"(",
"pfx",
"string",
",",
"prefixes",
"[",
"]",
"string",
")",
"[",
"]",
"listingItem",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"listingItem",
",",
"0",
",",
"len",
"(",
"prefixes",
")",
"+",
"1",
")",
"\n",
"if",
"pfx",
"!=",
"\"",
"\"",
"{",
"parent",
":=",
"\"",
"\"",
"\n",
"if",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"pfx",
",",
"\"",
"\"",
")",
";",
"idx",
"!=",
"-",
"1",
"{",
"parent",
"=",
"pfx",
"[",
":",
"idx",
"]",
"\n",
"}",
"\n",
"out",
"=",
"append",
"(",
"out",
",",
"listingItem",
"{",
"Back",
":",
"true",
",",
"Href",
":",
"prefixPageURL",
"(",
"parent",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"pathListing",
"(",
"pfx",
",",
"prefixes",
",",
"out",
",",
"func",
"(",
"p",
"string",
")",
"listingItem",
"{",
"return",
"listingItem",
"{",
"Href",
":",
"prefixPageURL",
"(",
"p",
")",
",",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // prefixesListing formats a list of child prefixes of 'pfx'.
//
// The result includes '..' if 'pfx' is not root. | [
"prefixesListing",
"formats",
"a",
"list",
"of",
"child",
"prefixes",
"of",
"pfx",
".",
"The",
"result",
"includes",
"..",
"if",
"pfx",
"is",
"not",
"root",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/appengine/ui/nav.go#L83-L100 |
9,355 | luci/luci-go | cipd/appengine/ui/nav.go | packagesListing | func packagesListing(pfx string, pkgs []string, active string) []listingItem {
out := make([]listingItem, 0, len(pkgs))
return pathListing(pfx, pkgs, out, func(p string) listingItem {
return listingItem{
Href: packagePageURL(p, ""),
Active: p == active,
}
})
} | go | func packagesListing(pfx string, pkgs []string, active string) []listingItem {
out := make([]listingItem, 0, len(pkgs))
return pathListing(pfx, pkgs, out, func(p string) listingItem {
return listingItem{
Href: packagePageURL(p, ""),
Active: p == active,
}
})
} | [
"func",
"packagesListing",
"(",
"pfx",
"string",
",",
"pkgs",
"[",
"]",
"string",
",",
"active",
"string",
")",
"[",
"]",
"listingItem",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"listingItem",
",",
"0",
",",
"len",
"(",
"pkgs",
")",
")",
"\n",
"return",
"pathListing",
"(",
"pfx",
",",
"pkgs",
",",
"out",
",",
"func",
"(",
"p",
"string",
")",
"listingItem",
"{",
"return",
"listingItem",
"{",
"Href",
":",
"packagePageURL",
"(",
"p",
",",
"\"",
"\"",
")",
",",
"Active",
":",
"p",
"==",
"active",
",",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // packagesListing formats a list of packages under 'pfx'.
//
// One of them can be hilighted as Active. | [
"packagesListing",
"formats",
"a",
"list",
"of",
"packages",
"under",
"pfx",
".",
"One",
"of",
"them",
"can",
"be",
"hilighted",
"as",
"Active",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/appengine/ui/nav.go#L105-L113 |
9,356 | luci/luci-go | client/cmd/swarming/common.go | Init | func (c *commonFlags) Init(authOpts auth.Options) {
c.defaultFlags.Init(&c.Flags)
c.authFlags.Register(&c.Flags, authOpts)
c.Flags.StringVar(&c.serverURL, "server", os.Getenv("SWARMING_SERVER"), "Server URL; required. Set $SWARMING_SERVER to set a default.")
c.Flags.IntVar(&c.worker, "worker", 8, "Number of workers used to download isolated files.")
} | go | func (c *commonFlags) Init(authOpts auth.Options) {
c.defaultFlags.Init(&c.Flags)
c.authFlags.Register(&c.Flags, authOpts)
c.Flags.StringVar(&c.serverURL, "server", os.Getenv("SWARMING_SERVER"), "Server URL; required. Set $SWARMING_SERVER to set a default.")
c.Flags.IntVar(&c.worker, "worker", 8, "Number of workers used to download isolated files.")
} | [
"func",
"(",
"c",
"*",
"commonFlags",
")",
"Init",
"(",
"authOpts",
"auth",
".",
"Options",
")",
"{",
"c",
".",
"defaultFlags",
".",
"Init",
"(",
"&",
"c",
".",
"Flags",
")",
"\n",
"c",
".",
"authFlags",
".",
"Register",
"(",
"&",
"c",
".",
"Flags",
",",
"authOpts",
")",
"\n",
"c",
".",
"Flags",
".",
"StringVar",
"(",
"&",
"c",
".",
"serverURL",
",",
"\"",
"\"",
",",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"c",
".",
"Flags",
".",
"IntVar",
"(",
"&",
"c",
".",
"worker",
",",
"\"",
"\"",
",",
"8",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Init initializes common flags. | [
"Init",
"initializes",
"common",
"flags",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/cmd/swarming/common.go#L179-L184 |
9,357 | luci/luci-go | client/cmd/swarming/common.go | Parse | func (c *commonFlags) Parse() error {
if err := c.defaultFlags.Parse(); err != nil {
return err
}
if c.serverURL == "" {
return errors.Reason("must provide -server").Err()
}
s, err := lhttp.CheckURL(c.serverURL)
if err != nil {
return err
}
c.serverURL = s
c.parsedAuthOpts, err = c.authFlags.Options()
return err
} | go | func (c *commonFlags) Parse() error {
if err := c.defaultFlags.Parse(); err != nil {
return err
}
if c.serverURL == "" {
return errors.Reason("must provide -server").Err()
}
s, err := lhttp.CheckURL(c.serverURL)
if err != nil {
return err
}
c.serverURL = s
c.parsedAuthOpts, err = c.authFlags.Options()
return err
} | [
"func",
"(",
"c",
"*",
"commonFlags",
")",
"Parse",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"c",
".",
"defaultFlags",
".",
"Parse",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
".",
"serverURL",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"s",
",",
"err",
":=",
"lhttp",
".",
"CheckURL",
"(",
"c",
".",
"serverURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"serverURL",
"=",
"s",
"\n",
"c",
".",
"parsedAuthOpts",
",",
"err",
"=",
"c",
".",
"authFlags",
".",
"Options",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Parse parses the common flags. | [
"Parse",
"parses",
"the",
"common",
"flags",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/cmd/swarming/common.go#L187-L201 |
9,358 | luci/luci-go | client/cmd/swarming/common.go | retryGoogleRPC | func retryGoogleRPC(ctx context.Context, rpcName string, rpc func() error) error {
return retry.Retry(ctx, transient.Only(retry.Default), func() error {
err := rpc()
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code >= 500 {
err = transient.Tag.Apply(err)
}
return err
}, retry.LogCallback(ctx, rpcName))
} | go | func retryGoogleRPC(ctx context.Context, rpcName string, rpc func() error) error {
return retry.Retry(ctx, transient.Only(retry.Default), func() error {
err := rpc()
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code >= 500 {
err = transient.Tag.Apply(err)
}
return err
}, retry.LogCallback(ctx, rpcName))
} | [
"func",
"retryGoogleRPC",
"(",
"ctx",
"context",
".",
"Context",
",",
"rpcName",
"string",
",",
"rpc",
"func",
"(",
")",
"error",
")",
"error",
"{",
"return",
"retry",
".",
"Retry",
"(",
"ctx",
",",
"transient",
".",
"Only",
"(",
"retry",
".",
"Default",
")",
",",
"func",
"(",
")",
"error",
"{",
"err",
":=",
"rpc",
"(",
")",
"\n",
"if",
"gerr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"googleapi",
".",
"Error",
")",
";",
"ok",
"&&",
"gerr",
".",
"Code",
">=",
"500",
"{",
"err",
"=",
"transient",
".",
"Tag",
".",
"Apply",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
",",
"retry",
".",
"LogCallback",
"(",
"ctx",
",",
"rpcName",
")",
")",
"\n",
"}"
] | // retryGoogleRPC retries an RPC on transient errors, such as HTTP 500. | [
"retryGoogleRPC",
"retries",
"an",
"RPC",
"on",
"transient",
"errors",
"such",
"as",
"HTTP",
"500",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/cmd/swarming/common.go#L237-L245 |
9,359 | luci/luci-go | machine-db/appengine/config/platforms.go | importPlatforms | func importPlatforms(c context.Context, configSet config.Set) (map[string]int64, error) {
platform := &configPB.Platforms{}
metadata := &config.Meta{}
if err := cfgclient.Get(c, cfgclient.AsService, configSet, platformsFilename, textproto.Message(platform), metadata); err != nil {
return nil, errors.Annotate(err, "failed to load %s", platformsFilename).Err()
}
logging.Infof(c, "Found %s revision %q", platformsFilename, metadata.Revision)
ctx := &validation.Context{Context: c}
ctx.SetFile(platformsFilename)
validatePlatforms(ctx, platform)
if err := ctx.Finalize(); err != nil {
return nil, errors.Annotate(err, "invalid config").Err()
}
ids, err := model.EnsurePlatforms(c, platform.Platform)
if err != nil {
return nil, errors.Annotate(err, "failed to ensure platforms").Err()
}
return ids, nil
} | go | func importPlatforms(c context.Context, configSet config.Set) (map[string]int64, error) {
platform := &configPB.Platforms{}
metadata := &config.Meta{}
if err := cfgclient.Get(c, cfgclient.AsService, configSet, platformsFilename, textproto.Message(platform), metadata); err != nil {
return nil, errors.Annotate(err, "failed to load %s", platformsFilename).Err()
}
logging.Infof(c, "Found %s revision %q", platformsFilename, metadata.Revision)
ctx := &validation.Context{Context: c}
ctx.SetFile(platformsFilename)
validatePlatforms(ctx, platform)
if err := ctx.Finalize(); err != nil {
return nil, errors.Annotate(err, "invalid config").Err()
}
ids, err := model.EnsurePlatforms(c, platform.Platform)
if err != nil {
return nil, errors.Annotate(err, "failed to ensure platforms").Err()
}
return ids, nil
} | [
"func",
"importPlatforms",
"(",
"c",
"context",
".",
"Context",
",",
"configSet",
"config",
".",
"Set",
")",
"(",
"map",
"[",
"string",
"]",
"int64",
",",
"error",
")",
"{",
"platform",
":=",
"&",
"configPB",
".",
"Platforms",
"{",
"}",
"\n",
"metadata",
":=",
"&",
"config",
".",
"Meta",
"{",
"}",
"\n",
"if",
"err",
":=",
"cfgclient",
".",
"Get",
"(",
"c",
",",
"cfgclient",
".",
"AsService",
",",
"configSet",
",",
"platformsFilename",
",",
"textproto",
".",
"Message",
"(",
"platform",
")",
",",
"metadata",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"platformsFilename",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"logging",
".",
"Infof",
"(",
"c",
",",
"\"",
"\"",
",",
"platformsFilename",
",",
"metadata",
".",
"Revision",
")",
"\n\n",
"ctx",
":=",
"&",
"validation",
".",
"Context",
"{",
"Context",
":",
"c",
"}",
"\n",
"ctx",
".",
"SetFile",
"(",
"platformsFilename",
")",
"\n",
"validatePlatforms",
"(",
"ctx",
",",
"platform",
")",
"\n",
"if",
"err",
":=",
"ctx",
".",
"Finalize",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n\n",
"ids",
",",
"err",
":=",
"model",
".",
"EnsurePlatforms",
"(",
"c",
",",
"platform",
".",
"Platform",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // importPlatforms fetches, validates, and applies platform configs.
// Returns a map of platform names to IDs. | [
"importPlatforms",
"fetches",
"validates",
"and",
"applies",
"platform",
"configs",
".",
"Returns",
"a",
"map",
"of",
"platform",
"names",
"to",
"IDs",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/config/platforms.go#L37-L57 |
9,360 | luci/luci-go | machine-db/appengine/config/platforms.go | validatePlatforms | func validatePlatforms(c *validation.Context, cfg *configPB.Platforms) {
// Platform names must be unique.
// Keep records of ones we've already seen.
names := stringset.New(len(cfg.Platform))
for _, p := range cfg.Platform {
switch {
case p.Name == "":
c.Errorf("platform names are required and must be non-empty")
case !names.Add(p.Name):
c.Errorf("duplicate platform %q", p.Name)
}
}
} | go | func validatePlatforms(c *validation.Context, cfg *configPB.Platforms) {
// Platform names must be unique.
// Keep records of ones we've already seen.
names := stringset.New(len(cfg.Platform))
for _, p := range cfg.Platform {
switch {
case p.Name == "":
c.Errorf("platform names are required and must be non-empty")
case !names.Add(p.Name):
c.Errorf("duplicate platform %q", p.Name)
}
}
} | [
"func",
"validatePlatforms",
"(",
"c",
"*",
"validation",
".",
"Context",
",",
"cfg",
"*",
"configPB",
".",
"Platforms",
")",
"{",
"// Platform names must be unique.",
"// Keep records of ones we've already seen.",
"names",
":=",
"stringset",
".",
"New",
"(",
"len",
"(",
"cfg",
".",
"Platform",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"cfg",
".",
"Platform",
"{",
"switch",
"{",
"case",
"p",
".",
"Name",
"==",
"\"",
"\"",
":",
"c",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"!",
"names",
".",
"Add",
"(",
"p",
".",
"Name",
")",
":",
"c",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // validatePlatforms validates platforms.cfg. | [
"validatePlatforms",
"validates",
"platforms",
".",
"cfg",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/config/platforms.go#L60-L72 |
9,361 | luci/luci-go | client/archiver/upload_tracker.go | newUploadTracker | func newUploadTracker(checker Checker, uploader Uploader, isol *isolated.Isolated) *UploadTracker {
isol.Files = make(map[string]isolated.File)
return &UploadTracker{
checker: checker,
uploader: uploader,
isol: isol,
fileHashCache: make(map[string]hashResult),
lOS: standardOS{},
}
} | go | func newUploadTracker(checker Checker, uploader Uploader, isol *isolated.Isolated) *UploadTracker {
isol.Files = make(map[string]isolated.File)
return &UploadTracker{
checker: checker,
uploader: uploader,
isol: isol,
fileHashCache: make(map[string]hashResult),
lOS: standardOS{},
}
} | [
"func",
"newUploadTracker",
"(",
"checker",
"Checker",
",",
"uploader",
"Uploader",
",",
"isol",
"*",
"isolated",
".",
"Isolated",
")",
"*",
"UploadTracker",
"{",
"isol",
".",
"Files",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"isolated",
".",
"File",
")",
"\n",
"return",
"&",
"UploadTracker",
"{",
"checker",
":",
"checker",
",",
"uploader",
":",
"uploader",
",",
"isol",
":",
"isol",
",",
"fileHashCache",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"hashResult",
")",
",",
"lOS",
":",
"standardOS",
"{",
"}",
",",
"}",
"\n",
"}"
] | // newUploadTracker constructs an UploadTracker. It tracks uploaded files in isol.Files. | [
"newUploadTracker",
"constructs",
"an",
"UploadTracker",
".",
"It",
"tracks",
"uploaded",
"files",
"in",
"isol",
".",
"Files",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L90-L99 |
9,362 | luci/luci-go | client/archiver/upload_tracker.go | UploadDeps | func (ut *UploadTracker) UploadDeps(parts partitionedDeps) error {
if err := ut.populateSymlinks(parts.links.items); err != nil {
return err
}
if err := ut.tarAndUploadFiles(parts.filesToArchive.items); err != nil {
return err
}
if err := ut.uploadFiles(parts.indivFiles.items); err != nil {
return err
}
return nil
} | go | func (ut *UploadTracker) UploadDeps(parts partitionedDeps) error {
if err := ut.populateSymlinks(parts.links.items); err != nil {
return err
}
if err := ut.tarAndUploadFiles(parts.filesToArchive.items); err != nil {
return err
}
if err := ut.uploadFiles(parts.indivFiles.items); err != nil {
return err
}
return nil
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"UploadDeps",
"(",
"parts",
"partitionedDeps",
")",
"error",
"{",
"if",
"err",
":=",
"ut",
".",
"populateSymlinks",
"(",
"parts",
".",
"links",
".",
"items",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ut",
".",
"tarAndUploadFiles",
"(",
"parts",
".",
"filesToArchive",
".",
"items",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ut",
".",
"uploadFiles",
"(",
"parts",
".",
"indivFiles",
".",
"items",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UploadDeps uploads all of the items in parts. | [
"UploadDeps",
"uploads",
"all",
"of",
"the",
"items",
"in",
"parts",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L102-L115 |
9,363 | luci/luci-go | client/archiver/upload_tracker.go | populateSymlinks | func (ut *UploadTracker) populateSymlinks(symlinks []*Item) error {
for _, item := range symlinks {
l, err := ut.lOS.Readlink(item.Path)
if err != nil {
return fmt.Errorf("unable to resolve symlink for %q: %v", item.Path, err)
}
ut.isol.Files[item.RelPath] = isolated.SymLink(l)
}
return nil
} | go | func (ut *UploadTracker) populateSymlinks(symlinks []*Item) error {
for _, item := range symlinks {
l, err := ut.lOS.Readlink(item.Path)
if err != nil {
return fmt.Errorf("unable to resolve symlink for %q: %v", item.Path, err)
}
ut.isol.Files[item.RelPath] = isolated.SymLink(l)
}
return nil
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"populateSymlinks",
"(",
"symlinks",
"[",
"]",
"*",
"Item",
")",
"error",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"symlinks",
"{",
"l",
",",
"err",
":=",
"ut",
".",
"lOS",
".",
"Readlink",
"(",
"item",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"item",
".",
"Path",
",",
"err",
")",
"\n",
"}",
"\n",
"ut",
".",
"isol",
".",
"Files",
"[",
"item",
".",
"RelPath",
"]",
"=",
"isolated",
".",
"SymLink",
"(",
"l",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // populateSymlinks adds an isolated.File to files for each provided symlink | [
"populateSymlinks",
"adds",
"an",
"isolated",
".",
"File",
"to",
"files",
"for",
"each",
"provided",
"symlink"
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L125-L134 |
9,364 | luci/luci-go | client/archiver/upload_tracker.go | tarAndUploadFiles | func (ut *UploadTracker) tarAndUploadFiles(smallFiles []*Item) error {
bundles := shardItems(smallFiles, archiveMaxSize)
log.Printf("\t%d TAR archives to be isolated", len(bundles))
for _, bundle := range bundles {
bundle := bundle
digest, tarSize, err := bundle.Digest(ut.checker.Hash())
if err != nil {
return err
}
log.Printf("Created tar archive %q (%s)", digest, humanize.Bytes(uint64(tarSize)))
log.Printf("\tcontains %d files (total %s)", len(bundle.items), humanize.Bytes(uint64(bundle.itemSize)))
// Mint an item for this tar.
item := &Item{
Path: fmt.Sprintf(".%s.tar", digest),
RelPath: fmt.Sprintf(".%s.tar", digest),
Size: tarSize,
Digest: digest,
}
ut.isol.Files[item.RelPath] = isolated.TarFile(item.Digest, item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
// We are about to upload item. If we fail, the entire isolate operation will fail.
// If we succeed, then item will be on the server by the time that the isolate operation
// completes. So it is safe for subsequent checks to assume that the item exists.
ut.checker.PresumeExists(item)
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.Upload(item.RelPath, bundle.Contents, ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
}
return nil
} | go | func (ut *UploadTracker) tarAndUploadFiles(smallFiles []*Item) error {
bundles := shardItems(smallFiles, archiveMaxSize)
log.Printf("\t%d TAR archives to be isolated", len(bundles))
for _, bundle := range bundles {
bundle := bundle
digest, tarSize, err := bundle.Digest(ut.checker.Hash())
if err != nil {
return err
}
log.Printf("Created tar archive %q (%s)", digest, humanize.Bytes(uint64(tarSize)))
log.Printf("\tcontains %d files (total %s)", len(bundle.items), humanize.Bytes(uint64(bundle.itemSize)))
// Mint an item for this tar.
item := &Item{
Path: fmt.Sprintf(".%s.tar", digest),
RelPath: fmt.Sprintf(".%s.tar", digest),
Size: tarSize,
Digest: digest,
}
ut.isol.Files[item.RelPath] = isolated.TarFile(item.Digest, item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
// We are about to upload item. If we fail, the entire isolate operation will fail.
// If we succeed, then item will be on the server by the time that the isolate operation
// completes. So it is safe for subsequent checks to assume that the item exists.
ut.checker.PresumeExists(item)
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.Upload(item.RelPath, bundle.Contents, ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
}
return nil
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"tarAndUploadFiles",
"(",
"smallFiles",
"[",
"]",
"*",
"Item",
")",
"error",
"{",
"bundles",
":=",
"shardItems",
"(",
"smallFiles",
",",
"archiveMaxSize",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"len",
"(",
"bundles",
")",
")",
"\n\n",
"for",
"_",
",",
"bundle",
":=",
"range",
"bundles",
"{",
"bundle",
":=",
"bundle",
"\n",
"digest",
",",
"tarSize",
",",
"err",
":=",
"bundle",
".",
"Digest",
"(",
"ut",
".",
"checker",
".",
"Hash",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"digest",
",",
"humanize",
".",
"Bytes",
"(",
"uint64",
"(",
"tarSize",
")",
")",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"len",
"(",
"bundle",
".",
"items",
")",
",",
"humanize",
".",
"Bytes",
"(",
"uint64",
"(",
"bundle",
".",
"itemSize",
")",
")",
")",
"\n",
"// Mint an item for this tar.",
"item",
":=",
"&",
"Item",
"{",
"Path",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"digest",
")",
",",
"RelPath",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"digest",
")",
",",
"Size",
":",
"tarSize",
",",
"Digest",
":",
"digest",
",",
"}",
"\n",
"ut",
".",
"isol",
".",
"Files",
"[",
"item",
".",
"RelPath",
"]",
"=",
"isolated",
".",
"TarFile",
"(",
"item",
".",
"Digest",
",",
"item",
".",
"Size",
")",
"\n\n",
"ut",
".",
"checker",
".",
"AddItem",
"(",
"item",
",",
"false",
",",
"func",
"(",
"item",
"*",
"Item",
",",
"ps",
"*",
"isolatedclient",
".",
"PushState",
")",
"{",
"if",
"ps",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// We are about to upload item. If we fail, the entire isolate operation will fail.",
"// If we succeed, then item will be on the server by the time that the isolate operation",
"// completes. So it is safe for subsequent checks to assume that the item exists.",
"ut",
".",
"checker",
".",
"PresumeExists",
"(",
"item",
")",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"ut",
".",
"uploader",
".",
"Upload",
"(",
"item",
".",
"RelPath",
",",
"bundle",
".",
"Contents",
",",
"ps",
",",
"func",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"}",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // tarAndUploadFiles creates bundles of files, uploads them, and adds each bundle to files. | [
"tarAndUploadFiles",
"creates",
"bundles",
"of",
"files",
"uploads",
"them",
"and",
"adds",
"each",
"bundle",
"to",
"files",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L137-L176 |
9,365 | luci/luci-go | client/archiver/upload_tracker.go | uploadFiles | func (ut *UploadTracker) uploadFiles(files []*Item) error {
// Handle the large individually-uploaded files.
for _, item := range files {
d, err := ut.hashFile(item.Path)
if err != nil {
return err
}
item.Digest = d
ut.isol.Files[item.RelPath] = isolated.BasicFile(item.Digest, int(item.Mode), item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
// We are about to upload item. If we fail, the entire isolate operation will fail.
// If we succeed, then item will be on the server by the time that the isolate operation
// completes. So it is safe for subsequent checks to assume that the item exists.
ut.checker.PresumeExists(item)
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.UploadFile(item, ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
}
return nil
} | go | func (ut *UploadTracker) uploadFiles(files []*Item) error {
// Handle the large individually-uploaded files.
for _, item := range files {
d, err := ut.hashFile(item.Path)
if err != nil {
return err
}
item.Digest = d
ut.isol.Files[item.RelPath] = isolated.BasicFile(item.Digest, int(item.Mode), item.Size)
ut.checker.AddItem(item, false, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
// We are about to upload item. If we fail, the entire isolate operation will fail.
// If we succeed, then item will be on the server by the time that the isolate operation
// completes. So it is safe for subsequent checks to assume that the item exists.
ut.checker.PresumeExists(item)
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.UploadFile(item, ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
}
return nil
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"uploadFiles",
"(",
"files",
"[",
"]",
"*",
"Item",
")",
"error",
"{",
"// Handle the large individually-uploaded files.",
"for",
"_",
",",
"item",
":=",
"range",
"files",
"{",
"d",
",",
"err",
":=",
"ut",
".",
"hashFile",
"(",
"item",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"item",
".",
"Digest",
"=",
"d",
"\n",
"ut",
".",
"isol",
".",
"Files",
"[",
"item",
".",
"RelPath",
"]",
"=",
"isolated",
".",
"BasicFile",
"(",
"item",
".",
"Digest",
",",
"int",
"(",
"item",
".",
"Mode",
")",
",",
"item",
".",
"Size",
")",
"\n",
"ut",
".",
"checker",
".",
"AddItem",
"(",
"item",
",",
"false",
",",
"func",
"(",
"item",
"*",
"Item",
",",
"ps",
"*",
"isolatedclient",
".",
"PushState",
")",
"{",
"if",
"ps",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// We are about to upload item. If we fail, the entire isolate operation will fail.",
"// If we succeed, then item will be on the server by the time that the isolate operation",
"// completes. So it is safe for subsequent checks to assume that the item exists.",
"ut",
".",
"checker",
".",
"PresumeExists",
"(",
"item",
")",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"ut",
".",
"uploader",
".",
"UploadFile",
"(",
"item",
",",
"ps",
",",
"func",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"}",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // uploadFiles uploads each file and adds it to files. | [
"uploadFiles",
"uploads",
"each",
"file",
"and",
"adds",
"it",
"to",
"files",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L179-L205 |
9,366 | luci/luci-go | client/archiver/upload_tracker.go | Finalize | func (ut *UploadTracker) Finalize(isolatedPath string) (IsolatedSummary, error) {
isolFile, err := newIsolatedFile(ut.isol, isolatedPath)
if err != nil {
return IsolatedSummary{}, err
}
// Check and upload isolate JSON.
ut.checker.AddItem(isolFile.item(ut.checker.Hash()), true, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.UploadBytes(item.RelPath, isolFile.contents(), ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
// Write the isolated file...
if isolFile.path != "" {
if err := isolFile.writeJSONFile(ut.lOS); err != nil {
return IsolatedSummary{}, err
}
}
return IsolatedSummary{
Name: isolFile.name(),
Digest: isolFile.item(ut.checker.Hash()).Digest,
}, nil
} | go | func (ut *UploadTracker) Finalize(isolatedPath string) (IsolatedSummary, error) {
isolFile, err := newIsolatedFile(ut.isol, isolatedPath)
if err != nil {
return IsolatedSummary{}, err
}
// Check and upload isolate JSON.
ut.checker.AddItem(isolFile.item(ut.checker.Hash()), true, func(item *Item, ps *isolatedclient.PushState) {
if ps == nil {
return
}
log.Printf("QUEUED %q for upload", item.RelPath)
ut.uploader.UploadBytes(item.RelPath, isolFile.contents(), ps, func() {
log.Printf("UPLOADED %q", item.RelPath)
})
})
// Write the isolated file...
if isolFile.path != "" {
if err := isolFile.writeJSONFile(ut.lOS); err != nil {
return IsolatedSummary{}, err
}
}
return IsolatedSummary{
Name: isolFile.name(),
Digest: isolFile.item(ut.checker.Hash()).Digest,
}, nil
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"Finalize",
"(",
"isolatedPath",
"string",
")",
"(",
"IsolatedSummary",
",",
"error",
")",
"{",
"isolFile",
",",
"err",
":=",
"newIsolatedFile",
"(",
"ut",
".",
"isol",
",",
"isolatedPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"IsolatedSummary",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"// Check and upload isolate JSON.",
"ut",
".",
"checker",
".",
"AddItem",
"(",
"isolFile",
".",
"item",
"(",
"ut",
".",
"checker",
".",
"Hash",
"(",
")",
")",
",",
"true",
",",
"func",
"(",
"item",
"*",
"Item",
",",
"ps",
"*",
"isolatedclient",
".",
"PushState",
")",
"{",
"if",
"ps",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"ut",
".",
"uploader",
".",
"UploadBytes",
"(",
"item",
".",
"RelPath",
",",
"isolFile",
".",
"contents",
"(",
")",
",",
"ps",
",",
"func",
"(",
")",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"item",
".",
"RelPath",
")",
"\n",
"}",
")",
"\n",
"}",
")",
"\n\n",
"// Write the isolated file...",
"if",
"isolFile",
".",
"path",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"isolFile",
".",
"writeJSONFile",
"(",
"ut",
".",
"lOS",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"IsolatedSummary",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"IsolatedSummary",
"{",
"Name",
":",
"isolFile",
".",
"name",
"(",
")",
",",
"Digest",
":",
"isolFile",
".",
"item",
"(",
"ut",
".",
"checker",
".",
"Hash",
"(",
")",
")",
".",
"Digest",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Finalize creates and uploads the isolate JSON at the isolatePath, and closes the checker and uploader.
// It returns the isolate name and digest.
// Finalize should only be called after UploadDeps. | [
"Finalize",
"creates",
"and",
"uploads",
"the",
"isolate",
"JSON",
"at",
"the",
"isolatePath",
"and",
"closes",
"the",
"checker",
"and",
"uploader",
".",
"It",
"returns",
"the",
"isolate",
"name",
"and",
"digest",
".",
"Finalize",
"should",
"only",
"be",
"called",
"after",
"UploadDeps",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L217-L245 |
9,367 | luci/luci-go | client/archiver/upload_tracker.go | hashFile | func (ut *UploadTracker) hashFile(path string) (isolated.HexDigest, error) {
if result, ok := ut.fileHashCache[path]; ok {
return result.digest, result.err
}
digest, err := ut.doHashFile(path)
ut.fileHashCache[path] = hashResult{digest, err}
return digest, err
} | go | func (ut *UploadTracker) hashFile(path string) (isolated.HexDigest, error) {
if result, ok := ut.fileHashCache[path]; ok {
return result.digest, result.err
}
digest, err := ut.doHashFile(path)
ut.fileHashCache[path] = hashResult{digest, err}
return digest, err
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"hashFile",
"(",
"path",
"string",
")",
"(",
"isolated",
".",
"HexDigest",
",",
"error",
")",
"{",
"if",
"result",
",",
"ok",
":=",
"ut",
".",
"fileHashCache",
"[",
"path",
"]",
";",
"ok",
"{",
"return",
"result",
".",
"digest",
",",
"result",
".",
"err",
"\n",
"}",
"\n\n",
"digest",
",",
"err",
":=",
"ut",
".",
"doHashFile",
"(",
"path",
")",
"\n",
"ut",
".",
"fileHashCache",
"[",
"path",
"]",
"=",
"hashResult",
"{",
"digest",
",",
"err",
"}",
"\n",
"return",
"digest",
",",
"err",
"\n",
"}"
] | // hashFile returns the hash of the contents of path, memoizing its results. | [
"hashFile",
"returns",
"the",
"hash",
"of",
"the",
"contents",
"of",
"path",
"memoizing",
"its",
"results",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L248-L256 |
9,368 | luci/luci-go | client/archiver/upload_tracker.go | doHashFile | func (ut *UploadTracker) doHashFile(path string) (isolated.HexDigest, error) {
f, err := ut.lOS.Open(path)
if err != nil {
return "", err
}
defer f.Close()
return isolated.Hash(ut.checker.Hash(), f)
} | go | func (ut *UploadTracker) doHashFile(path string) (isolated.HexDigest, error) {
f, err := ut.lOS.Open(path)
if err != nil {
return "", err
}
defer f.Close()
return isolated.Hash(ut.checker.Hash(), f)
} | [
"func",
"(",
"ut",
"*",
"UploadTracker",
")",
"doHashFile",
"(",
"path",
"string",
")",
"(",
"isolated",
".",
"HexDigest",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ut",
".",
"lOS",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"isolated",
".",
"Hash",
"(",
"ut",
".",
"checker",
".",
"Hash",
"(",
")",
",",
"f",
")",
"\n",
"}"
] | // doHashFile returns the hash of the contents of path. This should not be
// called directly; call hashFile instead. | [
"doHashFile",
"returns",
"the",
"hash",
"of",
"the",
"contents",
"of",
"path",
".",
"This",
"should",
"not",
"be",
"called",
"directly",
";",
"call",
"hashFile",
"instead",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L260-L267 |
9,369 | luci/luci-go | client/archiver/upload_tracker.go | writeJSONFile | func (ij *isolatedFile) writeJSONFile(opener openFiler) error {
f, err := opener.OpenFile(ij.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
_, err = io.Copy(f, bytes.NewBuffer(ij.json))
err2 := f.Close()
if err != nil {
return err
}
return err2
} | go | func (ij *isolatedFile) writeJSONFile(opener openFiler) error {
f, err := opener.OpenFile(ij.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
_, err = io.Copy(f, bytes.NewBuffer(ij.json))
err2 := f.Close()
if err != nil {
return err
}
return err2
} | [
"func",
"(",
"ij",
"*",
"isolatedFile",
")",
"writeJSONFile",
"(",
"opener",
"openFiler",
")",
"error",
"{",
"f",
",",
"err",
":=",
"opener",
".",
"OpenFile",
"(",
"ij",
".",
"path",
",",
"os",
".",
"O_RDWR",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
",",
"0644",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"f",
",",
"bytes",
".",
"NewBuffer",
"(",
"ij",
".",
"json",
")",
")",
"\n",
"err2",
":=",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"err2",
"\n",
"}"
] | // writeJSONFile writes the file contents to the filesystem. | [
"writeJSONFile",
"writes",
"the",
"file",
"contents",
"to",
"the",
"filesystem",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L300-L311 |
9,370 | luci/luci-go | client/archiver/upload_tracker.go | name | func (ij *isolatedFile) name() string {
name := filepath.Base(ij.path)
if i := strings.LastIndex(name, "."); i != -1 {
name = name[:i]
}
return name
} | go | func (ij *isolatedFile) name() string {
name := filepath.Base(ij.path)
if i := strings.LastIndex(name, "."); i != -1 {
name = name[:i]
}
return name
} | [
"func",
"(",
"ij",
"*",
"isolatedFile",
")",
"name",
"(",
")",
"string",
"{",
"name",
":=",
"filepath",
".",
"Base",
"(",
"ij",
".",
"path",
")",
"\n",
"if",
"i",
":=",
"strings",
".",
"LastIndex",
"(",
"name",
",",
"\"",
"\"",
")",
";",
"i",
"!=",
"-",
"1",
"{",
"name",
"=",
"name",
"[",
":",
"i",
"]",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
] | // name returns the base name of the isolated file, extension stripped. | [
"name",
"returns",
"the",
"base",
"name",
"of",
"the",
"isolated",
"file",
"extension",
"stripped",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/client/archiver/upload_tracker.go#L314-L320 |
9,371 | luci/luci-go | appengine/mapper/job.go | ToDatastoreQuery | func (q *Query) ToDatastoreQuery() *datastore.Query {
dq := datastore.NewQuery(q.Kind)
if q.Ancestor != nil {
dq = dq.Ancestor(q.Ancestor)
}
return dq
} | go | func (q *Query) ToDatastoreQuery() *datastore.Query {
dq := datastore.NewQuery(q.Kind)
if q.Ancestor != nil {
dq = dq.Ancestor(q.Ancestor)
}
return dq
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"ToDatastoreQuery",
"(",
")",
"*",
"datastore",
".",
"Query",
"{",
"dq",
":=",
"datastore",
".",
"NewQuery",
"(",
"q",
".",
"Kind",
")",
"\n",
"if",
"q",
".",
"Ancestor",
"!=",
"nil",
"{",
"dq",
"=",
"dq",
".",
"Ancestor",
"(",
"q",
".",
"Ancestor",
")",
"\n",
"}",
"\n",
"return",
"dq",
"\n",
"}"
] | // ToDatastoreQuery returns corresponding datastore.Query. | [
"ToDatastoreQuery",
"returns",
"corresponding",
"datastore",
".",
"Query",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L48-L54 |
9,372 | luci/luci-go | appengine/mapper/job.go | Validate | func (jc *JobConfig) Validate() error {
switch {
case jc.ShardCount < 1:
return errors.Reason("ShardCount should be >= 1, try 8").Err()
case jc.PageSize <= 0:
return errors.Reason("PageSize should be > 0, try 256").Err()
case jc.PagesPerTask < 0:
return errors.Reason("PagesPerTask should be >= 0, keep 0 for default").Err()
case jc.TaskDuration < 0:
return errors.Reason("TaskDuration should be >= 0, keep 0 for default").Err()
}
return nil
} | go | func (jc *JobConfig) Validate() error {
switch {
case jc.ShardCount < 1:
return errors.Reason("ShardCount should be >= 1, try 8").Err()
case jc.PageSize <= 0:
return errors.Reason("PageSize should be > 0, try 256").Err()
case jc.PagesPerTask < 0:
return errors.Reason("PagesPerTask should be >= 0, keep 0 for default").Err()
case jc.TaskDuration < 0:
return errors.Reason("TaskDuration should be >= 0, keep 0 for default").Err()
}
return nil
} | [
"func",
"(",
"jc",
"*",
"JobConfig",
")",
"Validate",
"(",
")",
"error",
"{",
"switch",
"{",
"case",
"jc",
".",
"ShardCount",
"<",
"1",
":",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"case",
"jc",
".",
"PageSize",
"<=",
"0",
":",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"case",
"jc",
".",
"PagesPerTask",
"<",
"0",
":",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"case",
"jc",
".",
"TaskDuration",
"<",
"0",
":",
"return",
"errors",
".",
"Reason",
"(",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate returns an error of the config is invalid.
//
// Mapper existence is not checked. | [
"Validate",
"returns",
"an",
"error",
"of",
"the",
"config",
"is",
"invalid",
".",
"Mapper",
"existence",
"is",
"not",
"checked",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L98-L110 |
9,373 | luci/luci-go | appengine/mapper/job.go | fetchShardIDs | func (j *Job) fetchShardIDs(c context.Context) ([]int64, error) {
l := shardList{Parent: datastore.KeyForObj(c, j)}
switch err := datastore.Get(c, &l); {
case err == datastore.ErrNoSuchEntity:
return nil, errors.Annotate(err, "broken state, no ShardList entity for job %d", j.ID).Err()
case err != nil:
return nil, errors.Annotate(err, "when fetching list of shards of job %d", j.ID).Tag(transient.Tag).Err()
default:
return l.Shards, nil
}
} | go | func (j *Job) fetchShardIDs(c context.Context) ([]int64, error) {
l := shardList{Parent: datastore.KeyForObj(c, j)}
switch err := datastore.Get(c, &l); {
case err == datastore.ErrNoSuchEntity:
return nil, errors.Annotate(err, "broken state, no ShardList entity for job %d", j.ID).Err()
case err != nil:
return nil, errors.Annotate(err, "when fetching list of shards of job %d", j.ID).Tag(transient.Tag).Err()
default:
return l.Shards, nil
}
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"fetchShardIDs",
"(",
"c",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"int64",
",",
"error",
")",
"{",
"l",
":=",
"shardList",
"{",
"Parent",
":",
"datastore",
".",
"KeyForObj",
"(",
"c",
",",
"j",
")",
"}",
"\n",
"switch",
"err",
":=",
"datastore",
".",
"Get",
"(",
"c",
",",
"&",
"l",
")",
";",
"{",
"case",
"err",
"==",
"datastore",
".",
"ErrNoSuchEntity",
":",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"j",
".",
"ID",
")",
".",
"Err",
"(",
")",
"\n",
"case",
"err",
"!=",
"nil",
":",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"j",
".",
"ID",
")",
".",
"Tag",
"(",
"transient",
".",
"Tag",
")",
".",
"Err",
"(",
")",
"\n",
"default",
":",
"return",
"l",
".",
"Shards",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // fetchShardIDs fetches IDs of the job shards. | [
"fetchShardIDs",
"fetches",
"IDs",
"of",
"the",
"job",
"shards",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L152-L162 |
9,374 | luci/luci-go | appengine/mapper/job.go | fetchShards | func (j *Job) fetchShards(c context.Context) ([]shard, error) {
ids, err := j.fetchShardIDs(c)
if err != nil {
return nil, err
}
shards := make([]shard, len(ids))
for idx, sid := range ids {
shards[idx].ID = sid
}
if err := datastore.Get(c, shards); err != nil {
return nil, errors.Annotate(err, "failed to fetch some shards of job %d", j.ID).Tag(transient.Tag).Err()
}
return shards, nil
} | go | func (j *Job) fetchShards(c context.Context) ([]shard, error) {
ids, err := j.fetchShardIDs(c)
if err != nil {
return nil, err
}
shards := make([]shard, len(ids))
for idx, sid := range ids {
shards[idx].ID = sid
}
if err := datastore.Get(c, shards); err != nil {
return nil, errors.Annotate(err, "failed to fetch some shards of job %d", j.ID).Tag(transient.Tag).Err()
}
return shards, nil
} | [
"func",
"(",
"j",
"*",
"Job",
")",
"fetchShards",
"(",
"c",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"shard",
",",
"error",
")",
"{",
"ids",
",",
"err",
":=",
"j",
".",
"fetchShardIDs",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"shards",
":=",
"make",
"(",
"[",
"]",
"shard",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"idx",
",",
"sid",
":=",
"range",
"ids",
"{",
"shards",
"[",
"idx",
"]",
".",
"ID",
"=",
"sid",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"datastore",
".",
"Get",
"(",
"c",
",",
"shards",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"j",
".",
"ID",
")",
".",
"Tag",
"(",
"transient",
".",
"Tag",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"return",
"shards",
",",
"nil",
"\n",
"}"
] | // fetchShards fetches all job shards. | [
"fetchShards",
"fetches",
"all",
"job",
"shards",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L165-L180 |
9,375 | luci/luci-go | appengine/mapper/job.go | getJob | func getJob(c context.Context, id JobID) (*Job, error) {
job := &Job{ID: id}
switch err := datastore.Get(c, job); {
case err == datastore.ErrNoSuchEntity:
return nil, ErrNoSuchJob
case err != nil:
return nil, errors.Annotate(err, "transient datastore error").Tag(transient.Tag).Err()
default:
return job, nil
}
} | go | func getJob(c context.Context, id JobID) (*Job, error) {
job := &Job{ID: id}
switch err := datastore.Get(c, job); {
case err == datastore.ErrNoSuchEntity:
return nil, ErrNoSuchJob
case err != nil:
return nil, errors.Annotate(err, "transient datastore error").Tag(transient.Tag).Err()
default:
return job, nil
}
} | [
"func",
"getJob",
"(",
"c",
"context",
".",
"Context",
",",
"id",
"JobID",
")",
"(",
"*",
"Job",
",",
"error",
")",
"{",
"job",
":=",
"&",
"Job",
"{",
"ID",
":",
"id",
"}",
"\n",
"switch",
"err",
":=",
"datastore",
".",
"Get",
"(",
"c",
",",
"job",
")",
";",
"{",
"case",
"err",
"==",
"datastore",
".",
"ErrNoSuchEntity",
":",
"return",
"nil",
",",
"ErrNoSuchJob",
"\n",
"case",
"err",
"!=",
"nil",
":",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Tag",
"(",
"transient",
".",
"Tag",
")",
".",
"Err",
"(",
")",
"\n",
"default",
":",
"return",
"job",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // getJob fetches a Job entity.
//
// Recognizes and tags transient errors. | [
"getJob",
"fetches",
"a",
"Job",
"entity",
".",
"Recognizes",
"and",
"tags",
"transient",
"errors",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L251-L261 |
9,376 | luci/luci-go | appengine/mapper/job.go | info | func (s *shard) info() *ShardInfo {
var rate float64
var eta *timestamp.Timestamp
if runtime := s.Updated.Sub(s.Created); runtime > 0 {
rate = float64(s.ProcessedCount) / runtime.Seconds()
if s.ExpectedCount != -1 && rate > 0.0001 {
secs := float64(s.ExpectedCount) / rate
eta = google.NewTimestamp(s.Created.Add(time.Duration(float64(time.Second) * secs)))
}
}
return &ShardInfo{
Index: int32(s.Index),
State: s.State,
Error: s.Error,
Created: google.NewTimestamp(s.Created),
Updated: google.NewTimestamp(s.Updated),
Eta: eta, // nil if unknown
ProcessedEntities: s.ProcessedCount,
TotalEntities: s.ExpectedCount, // -1 if unknown
EntitiesPerSec: float32(rate), // 0 if unknown
}
} | go | func (s *shard) info() *ShardInfo {
var rate float64
var eta *timestamp.Timestamp
if runtime := s.Updated.Sub(s.Created); runtime > 0 {
rate = float64(s.ProcessedCount) / runtime.Seconds()
if s.ExpectedCount != -1 && rate > 0.0001 {
secs := float64(s.ExpectedCount) / rate
eta = google.NewTimestamp(s.Created.Add(time.Duration(float64(time.Second) * secs)))
}
}
return &ShardInfo{
Index: int32(s.Index),
State: s.State,
Error: s.Error,
Created: google.NewTimestamp(s.Created),
Updated: google.NewTimestamp(s.Updated),
Eta: eta, // nil if unknown
ProcessedEntities: s.ProcessedCount,
TotalEntities: s.ExpectedCount, // -1 if unknown
EntitiesPerSec: float32(rate), // 0 if unknown
}
} | [
"func",
"(",
"s",
"*",
"shard",
")",
"info",
"(",
")",
"*",
"ShardInfo",
"{",
"var",
"rate",
"float64",
"\n",
"var",
"eta",
"*",
"timestamp",
".",
"Timestamp",
"\n\n",
"if",
"runtime",
":=",
"s",
".",
"Updated",
".",
"Sub",
"(",
"s",
".",
"Created",
")",
";",
"runtime",
">",
"0",
"{",
"rate",
"=",
"float64",
"(",
"s",
".",
"ProcessedCount",
")",
"/",
"runtime",
".",
"Seconds",
"(",
")",
"\n",
"if",
"s",
".",
"ExpectedCount",
"!=",
"-",
"1",
"&&",
"rate",
">",
"0.0001",
"{",
"secs",
":=",
"float64",
"(",
"s",
".",
"ExpectedCount",
")",
"/",
"rate",
"\n",
"eta",
"=",
"google",
".",
"NewTimestamp",
"(",
"s",
".",
"Created",
".",
"Add",
"(",
"time",
".",
"Duration",
"(",
"float64",
"(",
"time",
".",
"Second",
")",
"*",
"secs",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"ShardInfo",
"{",
"Index",
":",
"int32",
"(",
"s",
".",
"Index",
")",
",",
"State",
":",
"s",
".",
"State",
",",
"Error",
":",
"s",
".",
"Error",
",",
"Created",
":",
"google",
".",
"NewTimestamp",
"(",
"s",
".",
"Created",
")",
",",
"Updated",
":",
"google",
".",
"NewTimestamp",
"(",
"s",
".",
"Updated",
")",
",",
"Eta",
":",
"eta",
",",
"// nil if unknown",
"ProcessedEntities",
":",
"s",
".",
"ProcessedCount",
",",
"TotalEntities",
":",
"s",
".",
"ExpectedCount",
",",
"// -1 if unknown",
"EntitiesPerSec",
":",
"float32",
"(",
"rate",
")",
",",
"// 0 if unknown",
"}",
"\n",
"}"
] | // info returns a proto message with information about the shard. | [
"info",
"returns",
"a",
"proto",
"message",
"with",
"information",
"about",
"the",
"shard",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L324-L347 |
9,377 | luci/luci-go | appengine/mapper/job.go | shardTxn | func shardTxn(c context.Context, shardID int64, cb shardTxnCb) error {
return runTxn(c, func(c context.Context) error {
sh := shard{ID: shardID}
switch err := datastore.Get(c, &sh); {
case err == datastore.ErrNoSuchEntity:
return err
case err != nil:
return transient.Tag.Apply(err)
case isFinalState(sh.State):
return nil // the shard is already marked as done
}
switch save, err := cb(c, &sh); {
case err != nil:
return err
case !save:
return nil
default:
sh.Updated = clock.Now(c).UTC()
return transient.Tag.Apply(datastore.Put(c, &sh))
}
})
} | go | func shardTxn(c context.Context, shardID int64, cb shardTxnCb) error {
return runTxn(c, func(c context.Context) error {
sh := shard{ID: shardID}
switch err := datastore.Get(c, &sh); {
case err == datastore.ErrNoSuchEntity:
return err
case err != nil:
return transient.Tag.Apply(err)
case isFinalState(sh.State):
return nil // the shard is already marked as done
}
switch save, err := cb(c, &sh); {
case err != nil:
return err
case !save:
return nil
default:
sh.Updated = clock.Now(c).UTC()
return transient.Tag.Apply(datastore.Put(c, &sh))
}
})
} | [
"func",
"shardTxn",
"(",
"c",
"context",
".",
"Context",
",",
"shardID",
"int64",
",",
"cb",
"shardTxnCb",
")",
"error",
"{",
"return",
"runTxn",
"(",
"c",
",",
"func",
"(",
"c",
"context",
".",
"Context",
")",
"error",
"{",
"sh",
":=",
"shard",
"{",
"ID",
":",
"shardID",
"}",
"\n",
"switch",
"err",
":=",
"datastore",
".",
"Get",
"(",
"c",
",",
"&",
"sh",
")",
";",
"{",
"case",
"err",
"==",
"datastore",
".",
"ErrNoSuchEntity",
":",
"return",
"err",
"\n",
"case",
"err",
"!=",
"nil",
":",
"return",
"transient",
".",
"Tag",
".",
"Apply",
"(",
"err",
")",
"\n",
"case",
"isFinalState",
"(",
"sh",
".",
"State",
")",
":",
"return",
"nil",
"// the shard is already marked as done",
"\n",
"}",
"\n",
"switch",
"save",
",",
"err",
":=",
"cb",
"(",
"c",
",",
"&",
"sh",
")",
";",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"err",
"\n",
"case",
"!",
"save",
":",
"return",
"nil",
"\n",
"default",
":",
"sh",
".",
"Updated",
"=",
"clock",
".",
"Now",
"(",
"c",
")",
".",
"UTC",
"(",
")",
"\n",
"return",
"transient",
".",
"Tag",
".",
"Apply",
"(",
"datastore",
".",
"Put",
"(",
"c",
",",
"&",
"sh",
")",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // shardTxn fetches the shard and calls the callback to examine or mutate it.
//
// Silently skips finished shards. | [
"shardTxn",
"fetches",
"the",
"shard",
"and",
"calls",
"the",
"callback",
"to",
"examine",
"or",
"mutate",
"it",
".",
"Silently",
"skips",
"finished",
"shards",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/appengine/mapper/job.go#L384-L405 |
9,378 | luci/luci-go | machine-db/client/cli/racks.go | printRacks | func printRacks(tsv bool, racks ...*crimson.Rack) {
if len(racks) > 0 {
p := newStdoutPrinter(tsv)
defer p.Flush()
if !tsv {
p.Row("Name", "Datacenter", "Description", "State", "KVM")
}
for _, r := range racks {
p.Row(r.Name, r.Datacenter, r.Description, r.State, r.Kvm)
}
}
} | go | func printRacks(tsv bool, racks ...*crimson.Rack) {
if len(racks) > 0 {
p := newStdoutPrinter(tsv)
defer p.Flush()
if !tsv {
p.Row("Name", "Datacenter", "Description", "State", "KVM")
}
for _, r := range racks {
p.Row(r.Name, r.Datacenter, r.Description, r.State, r.Kvm)
}
}
} | [
"func",
"printRacks",
"(",
"tsv",
"bool",
",",
"racks",
"...",
"*",
"crimson",
".",
"Rack",
")",
"{",
"if",
"len",
"(",
"racks",
")",
">",
"0",
"{",
"p",
":=",
"newStdoutPrinter",
"(",
"tsv",
")",
"\n",
"defer",
"p",
".",
"Flush",
"(",
")",
"\n",
"if",
"!",
"tsv",
"{",
"p",
".",
"Row",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"racks",
"{",
"p",
".",
"Row",
"(",
"r",
".",
"Name",
",",
"r",
".",
"Datacenter",
",",
"r",
".",
"Description",
",",
"r",
".",
"State",
",",
"r",
".",
"Kvm",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // printRacks prints rack data to stdout in tab-separated columns. | [
"printRacks",
"prints",
"rack",
"data",
"to",
"stdout",
"in",
"tab",
"-",
"separated",
"columns",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/client/cli/racks.go#L28-L39 |
9,379 | luci/luci-go | machine-db/client/cli/racks.go | Run | func (c *GetRacksCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
ctx := cli.GetContext(app, c, env)
client := getClient(ctx)
resp, err := client.ListRacks(ctx, &c.req)
if err != nil {
errors.Log(ctx, err)
return 1
}
printRacks(c.f.tsv, resp.Racks...)
return 0
} | go | func (c *GetRacksCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
ctx := cli.GetContext(app, c, env)
client := getClient(ctx)
resp, err := client.ListRacks(ctx, &c.req)
if err != nil {
errors.Log(ctx, err)
return 1
}
printRacks(c.f.tsv, resp.Racks...)
return 0
} | [
"func",
"(",
"c",
"*",
"GetRacksCmd",
")",
"Run",
"(",
"app",
"subcommands",
".",
"Application",
",",
"args",
"[",
"]",
"string",
",",
"env",
"subcommands",
".",
"Env",
")",
"int",
"{",
"ctx",
":=",
"cli",
".",
"GetContext",
"(",
"app",
",",
"c",
",",
"env",
")",
"\n",
"client",
":=",
"getClient",
"(",
"ctx",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"ListRacks",
"(",
"ctx",
",",
"&",
"c",
".",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errors",
".",
"Log",
"(",
"ctx",
",",
"err",
")",
"\n",
"return",
"1",
"\n",
"}",
"\n",
"printRacks",
"(",
"c",
".",
"f",
".",
"tsv",
",",
"resp",
".",
"Racks",
"...",
")",
"\n",
"return",
"0",
"\n",
"}"
] | // Run runs the command to get racks. | [
"Run",
"runs",
"the",
"command",
"to",
"get",
"racks",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/client/cli/racks.go#L48-L58 |
9,380 | luci/luci-go | machine-db/client/cli/racks.go | getRacksCmd | func getRacksCmd(params *Parameters) *subcommands.Command {
return &subcommands.Command{
UsageLine: "get-racks [-name <name>]... [-dc <datacenter>]... [-kvm <kvm>]...",
ShortDesc: "retrieves racks",
LongDesc: "Retrieves racks matching the given names and dcs, or all racks if names and dcs are omitted.\n\nExample to get all racks:\ncrimson get-racks\nExample to get racks in datacenter xx1:\ncrimson get-racks -dc xx1",
CommandRun: func() subcommands.CommandRun {
cmd := &GetRacksCmd{}
cmd.Initialize(params)
cmd.Flags.Var(flag.StringSlice(&cmd.req.Names), "name", "Name of a rack to filter by. Can be specified multiple times.")
cmd.Flags.Var(flag.StringSlice(&cmd.req.Datacenters), "dc", "Name of a datacenter to filter by. Can be specified multiple times.")
cmd.Flags.Var(flag.StringSlice(&cmd.req.Kvms), "kvm", "Name of a KVM to filter by. Can be specified multiple times.")
return cmd
},
}
} | go | func getRacksCmd(params *Parameters) *subcommands.Command {
return &subcommands.Command{
UsageLine: "get-racks [-name <name>]... [-dc <datacenter>]... [-kvm <kvm>]...",
ShortDesc: "retrieves racks",
LongDesc: "Retrieves racks matching the given names and dcs, or all racks if names and dcs are omitted.\n\nExample to get all racks:\ncrimson get-racks\nExample to get racks in datacenter xx1:\ncrimson get-racks -dc xx1",
CommandRun: func() subcommands.CommandRun {
cmd := &GetRacksCmd{}
cmd.Initialize(params)
cmd.Flags.Var(flag.StringSlice(&cmd.req.Names), "name", "Name of a rack to filter by. Can be specified multiple times.")
cmd.Flags.Var(flag.StringSlice(&cmd.req.Datacenters), "dc", "Name of a datacenter to filter by. Can be specified multiple times.")
cmd.Flags.Var(flag.StringSlice(&cmd.req.Kvms), "kvm", "Name of a KVM to filter by. Can be specified multiple times.")
return cmd
},
}
} | [
"func",
"getRacksCmd",
"(",
"params",
"*",
"Parameters",
")",
"*",
"subcommands",
".",
"Command",
"{",
"return",
"&",
"subcommands",
".",
"Command",
"{",
"UsageLine",
":",
"\"",
"\"",
",",
"ShortDesc",
":",
"\"",
"\"",
",",
"LongDesc",
":",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"CommandRun",
":",
"func",
"(",
")",
"subcommands",
".",
"CommandRun",
"{",
"cmd",
":=",
"&",
"GetRacksCmd",
"{",
"}",
"\n",
"cmd",
".",
"Initialize",
"(",
"params",
")",
"\n",
"cmd",
".",
"Flags",
".",
"Var",
"(",
"flag",
".",
"StringSlice",
"(",
"&",
"cmd",
".",
"req",
".",
"Names",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Flags",
".",
"Var",
"(",
"flag",
".",
"StringSlice",
"(",
"&",
"cmd",
".",
"req",
".",
"Datacenters",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"cmd",
".",
"Flags",
".",
"Var",
"(",
"flag",
".",
"StringSlice",
"(",
"&",
"cmd",
".",
"req",
".",
"Kvms",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"cmd",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // getRacksCmd returns a command to get racks. | [
"getRacksCmd",
"returns",
"a",
"command",
"to",
"get",
"racks",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/client/cli/racks.go#L61-L75 |
9,381 | luci/luci-go | common/tsmon/flags.go | NewFlags | func NewFlags() Flags {
return Flags{
ConfigFile: defaultConfigFilePath(),
Endpoint: "",
Credentials: "",
ActAs: "",
Flush: FlushAuto,
FlushInterval: time.Minute,
Target: target.NewFlags(),
}
} | go | func NewFlags() Flags {
return Flags{
ConfigFile: defaultConfigFilePath(),
Endpoint: "",
Credentials: "",
ActAs: "",
Flush: FlushAuto,
FlushInterval: time.Minute,
Target: target.NewFlags(),
}
} | [
"func",
"NewFlags",
"(",
")",
"Flags",
"{",
"return",
"Flags",
"{",
"ConfigFile",
":",
"defaultConfigFilePath",
"(",
")",
",",
"Endpoint",
":",
"\"",
"\"",
",",
"Credentials",
":",
"\"",
"\"",
",",
"ActAs",
":",
"\"",
"\"",
",",
"Flush",
":",
"FlushAuto",
",",
"FlushInterval",
":",
"time",
".",
"Minute",
",",
"Target",
":",
"target",
".",
"NewFlags",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewFlags returns a Flags struct with sensible default values. | [
"NewFlags",
"returns",
"a",
"Flags",
"struct",
"with",
"sensible",
"default",
"values",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/flags.go#L38-L49 |
9,382 | luci/luci-go | common/tsmon/flags.go | Register | func (fl *Flags) Register(f *flag.FlagSet) {
f.StringVar(&fl.ConfigFile, "ts-mon-config-file", fl.ConfigFile,
"path to a JSON config file that contains suitable values for "+
"\"endpoint\" and \"credentials\" for this machine. This config file is "+
"intended to be shared by all processes on the machine, as the values "+
"depend on the machine's position in the network, IP whitelisting and "+
"deployment of credentials.")
f.StringVar(&fl.Endpoint, "ts-mon-endpoint", fl.Endpoint,
"url (including file://, https://, pubsub://project/topic) to post "+
"monitoring metrics to. If set, overrides the value in "+
"--ts-mon-config-file")
f.StringVar(&fl.Credentials, "ts-mon-credentials", fl.Credentials,
"path to a pkcs8 json credential file. If set, overrides the value in "+
"--ts-mon-config-file")
f.StringVar(&fl.ActAs, "ts-mon-act-as", fl.ActAs,
"(advanced) a service account email to impersonate when authenticating to "+
"tsmon backends. Uses 'iam' scope and serviceAccountTokenCreator role. "+
"If set, overrides the value in --ts-mon-config-file")
f.Var(&fl.Flush, "ts-mon-flush",
"metric push behavior: manual (only send when Flush() is called), or auto "+
"(send automatically every --ts-mon-flush-interval)")
f.DurationVar(&fl.FlushInterval, "ts-mon-flush-interval", fl.FlushInterval,
"automatically push metrics on this interval if --ts-mon-flush=auto")
fl.Target.Register(f)
} | go | func (fl *Flags) Register(f *flag.FlagSet) {
f.StringVar(&fl.ConfigFile, "ts-mon-config-file", fl.ConfigFile,
"path to a JSON config file that contains suitable values for "+
"\"endpoint\" and \"credentials\" for this machine. This config file is "+
"intended to be shared by all processes on the machine, as the values "+
"depend on the machine's position in the network, IP whitelisting and "+
"deployment of credentials.")
f.StringVar(&fl.Endpoint, "ts-mon-endpoint", fl.Endpoint,
"url (including file://, https://, pubsub://project/topic) to post "+
"monitoring metrics to. If set, overrides the value in "+
"--ts-mon-config-file")
f.StringVar(&fl.Credentials, "ts-mon-credentials", fl.Credentials,
"path to a pkcs8 json credential file. If set, overrides the value in "+
"--ts-mon-config-file")
f.StringVar(&fl.ActAs, "ts-mon-act-as", fl.ActAs,
"(advanced) a service account email to impersonate when authenticating to "+
"tsmon backends. Uses 'iam' scope and serviceAccountTokenCreator role. "+
"If set, overrides the value in --ts-mon-config-file")
f.Var(&fl.Flush, "ts-mon-flush",
"metric push behavior: manual (only send when Flush() is called), or auto "+
"(send automatically every --ts-mon-flush-interval)")
f.DurationVar(&fl.FlushInterval, "ts-mon-flush-interval", fl.FlushInterval,
"automatically push metrics on this interval if --ts-mon-flush=auto")
fl.Target.Register(f)
} | [
"func",
"(",
"fl",
"*",
"Flags",
")",
"Register",
"(",
"f",
"*",
"flag",
".",
"FlagSet",
")",
"{",
"f",
".",
"StringVar",
"(",
"&",
"fl",
".",
"ConfigFile",
",",
"\"",
"\"",
",",
"fl",
".",
"ConfigFile",
",",
"\"",
"\"",
"+",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"f",
".",
"StringVar",
"(",
"&",
"fl",
".",
"Endpoint",
",",
"\"",
"\"",
",",
"fl",
".",
"Endpoint",
",",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"f",
".",
"StringVar",
"(",
"&",
"fl",
".",
"Credentials",
",",
"\"",
"\"",
",",
"fl",
".",
"Credentials",
",",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"f",
".",
"StringVar",
"(",
"&",
"fl",
".",
"ActAs",
",",
"\"",
"\"",
",",
"fl",
".",
"ActAs",
",",
"\"",
"\"",
"+",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"f",
".",
"Var",
"(",
"&",
"fl",
".",
"Flush",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"\"",
"\"",
")",
"\n",
"f",
".",
"DurationVar",
"(",
"&",
"fl",
".",
"FlushInterval",
",",
"\"",
"\"",
",",
"fl",
".",
"FlushInterval",
",",
"\"",
"\"",
")",
"\n\n",
"fl",
".",
"Target",
".",
"Register",
"(",
"f",
")",
"\n",
"}"
] | // Register adds tsmon related flags to a FlagSet. | [
"Register",
"adds",
"tsmon",
"related",
"flags",
"to",
"a",
"FlagSet",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/tsmon/flags.go#L52-L77 |
9,383 | luci/luci-go | common/data/text/pattern/pattern.go | MustParse | func MustParse(s string) Pattern {
pattern, err := Parse(s)
if err != nil {
panic(err)
}
return pattern
} | go | func MustParse(s string) Pattern {
pattern, err := Parse(s)
if err != nil {
panic(err)
}
return pattern
} | [
"func",
"MustParse",
"(",
"s",
"string",
")",
"Pattern",
"{",
"pattern",
",",
"err",
":=",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"pattern",
"\n",
"}"
] | // MustParse parses the pattern according to the specification
// of Parse. In addition, it panics if there is an error in parsing the
// given string as a pattern.
//
// See Parse for more details. | [
"MustParse",
"parses",
"the",
"pattern",
"according",
"to",
"the",
"specification",
"of",
"Parse",
".",
"In",
"addition",
"it",
"panics",
"if",
"there",
"is",
"an",
"error",
"in",
"parsing",
"the",
"given",
"string",
"as",
"a",
"pattern",
".",
"See",
"Parse",
"for",
"more",
"details",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/common/data/text/pattern/pattern.go#L91-L97 |
9,384 | luci/luci-go | cipd/client/cipd/reader/reader.go | OpenInstance | func OpenInstance(ctx context.Context, r pkg.Source, opts OpenInstanceOpts) (pkg.Instance, error) {
out := &packageInstance{data: r}
if err := out.open(opts); err != nil {
return nil, err
}
return out, nil
} | go | func OpenInstance(ctx context.Context, r pkg.Source, opts OpenInstanceOpts) (pkg.Instance, error) {
out := &packageInstance{data: r}
if err := out.open(opts); err != nil {
return nil, err
}
return out, nil
} | [
"func",
"OpenInstance",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"pkg",
".",
"Source",
",",
"opts",
"OpenInstanceOpts",
")",
"(",
"pkg",
".",
"Instance",
",",
"error",
")",
"{",
"out",
":=",
"&",
"packageInstance",
"{",
"data",
":",
"r",
"}",
"\n",
"if",
"err",
":=",
"out",
".",
"open",
"(",
"opts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // OpenInstance opens a package instance by reading it from the given source.
//
// The caller is responsible for closing the instance when done with it.
//
// On success it takes ownership of the source, closing it when the instance
// itself is closed. On errors the source is left open. It's a responsibility of
// the caller to close it in this case. | [
"OpenInstance",
"opens",
"a",
"package",
"instance",
"by",
"reading",
"it",
"from",
"the",
"given",
"source",
".",
"The",
"caller",
"is",
"responsible",
"for",
"closing",
"the",
"instance",
"when",
"done",
"with",
"it",
".",
"On",
"success",
"it",
"takes",
"ownership",
"of",
"the",
"source",
"closing",
"it",
"when",
"the",
"instance",
"itself",
"is",
"closed",
".",
"On",
"errors",
"the",
"source",
"is",
"left",
"open",
".",
"It",
"s",
"a",
"responsibility",
"of",
"the",
"caller",
"to",
"close",
"it",
"in",
"this",
"case",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L99-L105 |
9,385 | luci/luci-go | cipd/client/cipd/reader/reader.go | OpenInstanceFile | func OpenInstanceFile(ctx context.Context, path string, opts OpenInstanceOpts) (pkg.Instance, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
inst, err := OpenInstance(ctx, fileSource{file}, opts)
if err != nil {
file.Close()
return nil, err
}
return inst, nil
} | go | func OpenInstanceFile(ctx context.Context, path string, opts OpenInstanceOpts) (pkg.Instance, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
inst, err := OpenInstance(ctx, fileSource{file}, opts)
if err != nil {
file.Close()
return nil, err
}
return inst, nil
} | [
"func",
"OpenInstanceFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
",",
"opts",
"OpenInstanceOpts",
")",
"(",
"pkg",
".",
"Instance",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"inst",
",",
"err",
":=",
"OpenInstance",
"(",
"ctx",
",",
"fileSource",
"{",
"file",
"}",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"file",
".",
"Close",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"inst",
",",
"nil",
"\n",
"}"
] | // OpenInstanceFile opens a package instance by reading it from a file on disk.
//
// The caller is responsible for closing the instance when done with it. This
// will close the underlying file too. | [
"OpenInstanceFile",
"opens",
"a",
"package",
"instance",
"by",
"reading",
"it",
"from",
"a",
"file",
"on",
"disk",
".",
"The",
"caller",
"is",
"responsible",
"for",
"closing",
"the",
"instance",
"when",
"done",
"with",
"it",
".",
"This",
"will",
"close",
"the",
"underlying",
"file",
"too",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L117-L128 |
9,386 | luci/luci-go | cipd/client/cipd/reader/reader.go | ExtractFilesTxn | func ExtractFilesTxn(ctx context.Context, files []fs.File, dest fs.TransactionalDestination, withManifest pkg.ManifestMode) (extracted []pkg.FileInfo, err error) {
if err := dest.Begin(ctx); err != nil {
return nil, err
}
// Cleanup the garbage even on panics.
defer func() {
endErr := dest.End(ctx, err == nil)
if err == nil {
err = endErr
} else if endErr != nil {
// Log endErr, but return the original error from ExtractFiles.
logging.Warningf(ctx, "Failed to cleanup the destination after failed extraction - %s", endErr)
}
}()
return ExtractFiles(ctx, files, dest, withManifest)
} | go | func ExtractFilesTxn(ctx context.Context, files []fs.File, dest fs.TransactionalDestination, withManifest pkg.ManifestMode) (extracted []pkg.FileInfo, err error) {
if err := dest.Begin(ctx); err != nil {
return nil, err
}
// Cleanup the garbage even on panics.
defer func() {
endErr := dest.End(ctx, err == nil)
if err == nil {
err = endErr
} else if endErr != nil {
// Log endErr, but return the original error from ExtractFiles.
logging.Warningf(ctx, "Failed to cleanup the destination after failed extraction - %s", endErr)
}
}()
return ExtractFiles(ctx, files, dest, withManifest)
} | [
"func",
"ExtractFilesTxn",
"(",
"ctx",
"context",
".",
"Context",
",",
"files",
"[",
"]",
"fs",
".",
"File",
",",
"dest",
"fs",
".",
"TransactionalDestination",
",",
"withManifest",
"pkg",
".",
"ManifestMode",
")",
"(",
"extracted",
"[",
"]",
"pkg",
".",
"FileInfo",
",",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"dest",
".",
"Begin",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Cleanup the garbage even on panics.",
"defer",
"func",
"(",
")",
"{",
"endErr",
":=",
"dest",
".",
"End",
"(",
"ctx",
",",
"err",
"==",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"endErr",
"\n",
"}",
"else",
"if",
"endErr",
"!=",
"nil",
"{",
"// Log endErr, but return the original error from ExtractFiles.",
"logging",
".",
"Warningf",
"(",
"ctx",
",",
"\"",
"\"",
",",
"endErr",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"ExtractFiles",
"(",
"ctx",
",",
"files",
",",
"dest",
",",
"withManifest",
")",
"\n",
"}"
] | // ExtractFilesTxn is like ExtractFiles, but it also opens and closes
// the transaction over fs.TransactionalDestination object.
//
// It guarantees that if extraction fails for some reason, there'll be no
// garbage laying around. | [
"ExtractFilesTxn",
"is",
"like",
"ExtractFiles",
"but",
"it",
"also",
"opens",
"and",
"closes",
"the",
"transaction",
"over",
"fs",
".",
"TransactionalDestination",
"object",
".",
"It",
"guarantees",
"that",
"if",
"extraction",
"fails",
"for",
"some",
"reason",
"there",
"ll",
"be",
"no",
"garbage",
"laying",
"around",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L282-L299 |
9,387 | luci/luci-go | cipd/client/cipd/reader/reader.go | advance | func (r *progressReporter) advance(f fs.File) {
if r.totalCount == 0 {
return
}
now := clock.Now(r.ctx)
reportNow := false
progress := 0
// We don't count size of the symlinks toward total.
var size uint64
if !f.Symlink() {
size = f.Size()
}
// Report progress on first and last 'advance' calls and each 2 sec.
r.Lock()
r.extractedSize += size
r.extractedCount++
if r.extractedCount == 1 || r.extractedCount == r.totalCount || now.Sub(r.prevReport) > 2*time.Second {
reportNow = true
if r.totalSize != 0 {
progress = int(float64(r.extractedSize) * 100 / float64(r.totalSize))
} else {
progress = int(float64(r.extractedCount) * 100 / float64(r.totalCount))
}
r.prevReport = now
}
r.Unlock()
if reportNow {
logging.Infof(r.ctx, "cipd: extracting - %d%%", progress)
}
} | go | func (r *progressReporter) advance(f fs.File) {
if r.totalCount == 0 {
return
}
now := clock.Now(r.ctx)
reportNow := false
progress := 0
// We don't count size of the symlinks toward total.
var size uint64
if !f.Symlink() {
size = f.Size()
}
// Report progress on first and last 'advance' calls and each 2 sec.
r.Lock()
r.extractedSize += size
r.extractedCount++
if r.extractedCount == 1 || r.extractedCount == r.totalCount || now.Sub(r.prevReport) > 2*time.Second {
reportNow = true
if r.totalSize != 0 {
progress = int(float64(r.extractedSize) * 100 / float64(r.totalSize))
} else {
progress = int(float64(r.extractedCount) * 100 / float64(r.totalCount))
}
r.prevReport = now
}
r.Unlock()
if reportNow {
logging.Infof(r.ctx, "cipd: extracting - %d%%", progress)
}
} | [
"func",
"(",
"r",
"*",
"progressReporter",
")",
"advance",
"(",
"f",
"fs",
".",
"File",
")",
"{",
"if",
"r",
".",
"totalCount",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"now",
":=",
"clock",
".",
"Now",
"(",
"r",
".",
"ctx",
")",
"\n",
"reportNow",
":=",
"false",
"\n",
"progress",
":=",
"0",
"\n\n",
"// We don't count size of the symlinks toward total.",
"var",
"size",
"uint64",
"\n",
"if",
"!",
"f",
".",
"Symlink",
"(",
")",
"{",
"size",
"=",
"f",
".",
"Size",
"(",
")",
"\n",
"}",
"\n\n",
"// Report progress on first and last 'advance' calls and each 2 sec.",
"r",
".",
"Lock",
"(",
")",
"\n",
"r",
".",
"extractedSize",
"+=",
"size",
"\n",
"r",
".",
"extractedCount",
"++",
"\n",
"if",
"r",
".",
"extractedCount",
"==",
"1",
"||",
"r",
".",
"extractedCount",
"==",
"r",
".",
"totalCount",
"||",
"now",
".",
"Sub",
"(",
"r",
".",
"prevReport",
")",
">",
"2",
"*",
"time",
".",
"Second",
"{",
"reportNow",
"=",
"true",
"\n",
"if",
"r",
".",
"totalSize",
"!=",
"0",
"{",
"progress",
"=",
"int",
"(",
"float64",
"(",
"r",
".",
"extractedSize",
")",
"*",
"100",
"/",
"float64",
"(",
"r",
".",
"totalSize",
")",
")",
"\n",
"}",
"else",
"{",
"progress",
"=",
"int",
"(",
"float64",
"(",
"r",
".",
"extractedCount",
")",
"*",
"100",
"/",
"float64",
"(",
"r",
".",
"totalCount",
")",
")",
"\n",
"}",
"\n",
"r",
".",
"prevReport",
"=",
"now",
"\n",
"}",
"\n",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"reportNow",
"{",
"logging",
".",
"Infof",
"(",
"r",
".",
"ctx",
",",
"\"",
"\"",
",",
"progress",
")",
"\n",
"}",
"\n",
"}"
] | // advance moves the progress indicator, occasionally logging it. | [
"advance",
"moves",
"the",
"progress",
"indicator",
"occasionally",
"logging",
"it",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L332-L365 |
9,388 | luci/luci-go | cipd/client/cipd/reader/reader.go | IsCorruptionError | func IsCorruptionError(err error) bool {
switch err {
case io.ErrUnexpectedEOF, zip.ErrFormat, zip.ErrChecksum, zip.ErrAlgorithm, ErrHashMismatch:
return true
}
return false
} | go | func IsCorruptionError(err error) bool {
switch err {
case io.ErrUnexpectedEOF, zip.ErrFormat, zip.ErrChecksum, zip.ErrAlgorithm, ErrHashMismatch:
return true
}
return false
} | [
"func",
"IsCorruptionError",
"(",
"err",
"error",
")",
"bool",
"{",
"switch",
"err",
"{",
"case",
"io",
".",
"ErrUnexpectedEOF",
",",
"zip",
".",
"ErrFormat",
",",
"zip",
".",
"ErrChecksum",
",",
"zip",
".",
"ErrAlgorithm",
",",
"ErrHashMismatch",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsCorruptionError returns true iff err indicates corruption. | [
"IsCorruptionError",
"returns",
"true",
"iff",
"err",
"indicates",
"corruption",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L527-L533 |
9,389 | luci/luci-go | cipd/client/cipd/reader/reader.go | readManifestFile | func readManifestFile(f fs.File) (pkg.Manifest, error) {
r, err := f.Open()
if err != nil {
return pkg.Manifest{}, err
}
defer r.Close()
return pkg.ReadManifest(r)
} | go | func readManifestFile(f fs.File) (pkg.Manifest, error) {
r, err := f.Open()
if err != nil {
return pkg.Manifest{}, err
}
defer r.Close()
return pkg.ReadManifest(r)
} | [
"func",
"readManifestFile",
"(",
"f",
"fs",
".",
"File",
")",
"(",
"pkg",
".",
"Manifest",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"f",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"pkg",
".",
"Manifest",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"Close",
"(",
")",
"\n",
"return",
"pkg",
".",
"ReadManifest",
"(",
"r",
")",
"\n",
"}"
] | // readManifestFile decodes manifest file zipped inside the package. | [
"readManifestFile",
"decodes",
"manifest",
"file",
"zipped",
"inside",
"the",
"package",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L552-L559 |
9,390 | luci/luci-go | cipd/client/cipd/reader/reader.go | makeVersionFile | func makeVersionFile(relPath string, versionFile pkg.VersionFile) (fs.File, error) {
if !fs.IsCleanSlashPath(relPath) {
return nil, fmt.Errorf("invalid version_file: %s", relPath)
}
blob, err := json.MarshalIndent(versionFile, "", " ")
if err != nil {
return nil, err
}
return &blobFile{
name: relPath,
blob: blob,
}, nil
} | go | func makeVersionFile(relPath string, versionFile pkg.VersionFile) (fs.File, error) {
if !fs.IsCleanSlashPath(relPath) {
return nil, fmt.Errorf("invalid version_file: %s", relPath)
}
blob, err := json.MarshalIndent(versionFile, "", " ")
if err != nil {
return nil, err
}
return &blobFile{
name: relPath,
blob: blob,
}, nil
} | [
"func",
"makeVersionFile",
"(",
"relPath",
"string",
",",
"versionFile",
"pkg",
".",
"VersionFile",
")",
"(",
"fs",
".",
"File",
",",
"error",
")",
"{",
"if",
"!",
"fs",
".",
"IsCleanSlashPath",
"(",
"relPath",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"relPath",
")",
"\n",
"}",
"\n",
"blob",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"versionFile",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"blobFile",
"{",
"name",
":",
"relPath",
",",
"blob",
":",
"blob",
",",
"}",
",",
"nil",
"\n",
"}"
] | // makeVersionFile returns File representing a JSON blob with info about package
// version. It's what's deployed at path specified in 'version_file' stanza in
// package definition YAML. | [
"makeVersionFile",
"returns",
"File",
"representing",
"a",
"JSON",
"blob",
"with",
"info",
"about",
"package",
"version",
".",
"It",
"s",
"what",
"s",
"deployed",
"at",
"path",
"specified",
"in",
"version_file",
"stanza",
"in",
"package",
"definition",
"YAML",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L564-L576 |
9,391 | luci/luci-go | cipd/client/cipd/reader/reader.go | prefetch | func (f *fileInZip) prefetch() error {
if f.body != nil {
return nil
}
r, err := f.z.Open()
if err != nil {
return err
}
defer r.Close()
f.body, err = ioutil.ReadAll(r)
return err
} | go | func (f *fileInZip) prefetch() error {
if f.body != nil {
return nil
}
r, err := f.z.Open()
if err != nil {
return err
}
defer r.Close()
f.body, err = ioutil.ReadAll(r)
return err
} | [
"func",
"(",
"f",
"*",
"fileInZip",
")",
"prefetch",
"(",
")",
"error",
"{",
"if",
"f",
".",
"body",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"r",
",",
"err",
":=",
"f",
".",
"z",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"r",
".",
"Close",
"(",
")",
"\n",
"f",
".",
"body",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // prefetch loads the body of file into memory to speed up later calls. | [
"prefetch",
"loads",
"the",
"body",
"of",
"file",
"into",
"memory",
"to",
"speed",
"up",
"later",
"calls",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/cipd/client/cipd/reader/reader.go#L606-L617 |
9,392 | luci/luci-go | milo/git/combined_logs.go | pop | func (rc *refCommits) pop() (commit *gitpb.Commit, empty bool) {
commit, rc.commits = rc.commits[0], rc.commits[1:]
return commit, len(rc.commits) == 0
} | go | func (rc *refCommits) pop() (commit *gitpb.Commit, empty bool) {
commit, rc.commits = rc.commits[0], rc.commits[1:]
return commit, len(rc.commits) == 0
} | [
"func",
"(",
"rc",
"*",
"refCommits",
")",
"pop",
"(",
")",
"(",
"commit",
"*",
"gitpb",
".",
"Commit",
",",
"empty",
"bool",
")",
"{",
"commit",
",",
"rc",
".",
"commits",
"=",
"rc",
".",
"commits",
"[",
"0",
"]",
",",
"rc",
".",
"commits",
"[",
"1",
":",
"]",
"\n",
"return",
"commit",
",",
"len",
"(",
"rc",
".",
"commits",
")",
"==",
"0",
"\n",
"}"
] | // The pop method removes and returns first commit. Second return value is true
// if this was the last commit. Caller must ensure refCommits has commits when
// calling the method. | [
"The",
"pop",
"method",
"removes",
"and",
"returns",
"first",
"commit",
".",
"Second",
"return",
"value",
"is",
"true",
"if",
"this",
"was",
"the",
"last",
"commit",
".",
"Caller",
"must",
"ensure",
"refCommits",
"has",
"commits",
"when",
"calling",
"the",
"method",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/git/combined_logs.go#L46-L49 |
9,393 | luci/luci-go | milo/git/combined_logs.go | CombinedLogs | func (impl *implementation) CombinedLogs(c context.Context, host, project, excludeRef string, refs []string, limit int) (commits []*gitpb.Commit, err error) {
defer func() { err = errors.Annotate(common.TagGRPC(c, err), "gitiles.CombinedLogs").Err() }()
// Check if the user is allowed to access this project.
allowed, err := impl.acls.IsAllowed(c, host, project)
switch {
case err != nil:
return
case !allowed:
err = status.Errorf(codes.NotFound, "not found")
return
}
// Prepare Gitiles client.
client, err := impl.gitilesClient(c, host)
if err != nil {
return
}
// Resolve all refs and commits they are pointing at.
refTips, missingRefs, err := gitilesapi.NewRefSet(refs).Resolve(c, client, project)
if err != nil {
return
}
if len(missingRefs) > 0 {
logging.Warningf(c, "configured refs %s weren't resolved to any ref; either incorrect ACLs or redudant refs", missingRefs)
}
var logs [][]*gitpb.Commit
if logs, err = impl.loadLogsForRefs(c, host, project, excludeRef, limit, refTips); err != nil {
return
}
// We merge commits from all refs sorted by time into a single list up to a
// limit. We use max-heap based merging algorithm below.
var h commitHeap
for _, log := range logs {
if len(log) > 0 {
h = append(h, refCommits{log})
}
}
// Keep adding commits to the merged list until we reach the limit or run out
// of commits on all refs.
heap.Init(&h)
commits = make([]*gitpb.Commit, 0, limit)
for len(commits) < limit && len(h) != 0 {
commit, empty := h[0].pop()
// Do not add duplicate commits that come from different refs.
if len(commits) == 0 || commits[len(commits)-1].Id != commit.Id {
commits = append(commits, commit)
}
if empty {
heap.Remove(&h, 0)
} else {
heap.Fix(&h, 0)
}
}
return
} | go | func (impl *implementation) CombinedLogs(c context.Context, host, project, excludeRef string, refs []string, limit int) (commits []*gitpb.Commit, err error) {
defer func() { err = errors.Annotate(common.TagGRPC(c, err), "gitiles.CombinedLogs").Err() }()
// Check if the user is allowed to access this project.
allowed, err := impl.acls.IsAllowed(c, host, project)
switch {
case err != nil:
return
case !allowed:
err = status.Errorf(codes.NotFound, "not found")
return
}
// Prepare Gitiles client.
client, err := impl.gitilesClient(c, host)
if err != nil {
return
}
// Resolve all refs and commits they are pointing at.
refTips, missingRefs, err := gitilesapi.NewRefSet(refs).Resolve(c, client, project)
if err != nil {
return
}
if len(missingRefs) > 0 {
logging.Warningf(c, "configured refs %s weren't resolved to any ref; either incorrect ACLs or redudant refs", missingRefs)
}
var logs [][]*gitpb.Commit
if logs, err = impl.loadLogsForRefs(c, host, project, excludeRef, limit, refTips); err != nil {
return
}
// We merge commits from all refs sorted by time into a single list up to a
// limit. We use max-heap based merging algorithm below.
var h commitHeap
for _, log := range logs {
if len(log) > 0 {
h = append(h, refCommits{log})
}
}
// Keep adding commits to the merged list until we reach the limit or run out
// of commits on all refs.
heap.Init(&h)
commits = make([]*gitpb.Commit, 0, limit)
for len(commits) < limit && len(h) != 0 {
commit, empty := h[0].pop()
// Do not add duplicate commits that come from different refs.
if len(commits) == 0 || commits[len(commits)-1].Id != commit.Id {
commits = append(commits, commit)
}
if empty {
heap.Remove(&h, 0)
} else {
heap.Fix(&h, 0)
}
}
return
} | [
"func",
"(",
"impl",
"*",
"implementation",
")",
"CombinedLogs",
"(",
"c",
"context",
".",
"Context",
",",
"host",
",",
"project",
",",
"excludeRef",
"string",
",",
"refs",
"[",
"]",
"string",
",",
"limit",
"int",
")",
"(",
"commits",
"[",
"]",
"*",
"gitpb",
".",
"Commit",
",",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"err",
"=",
"errors",
".",
"Annotate",
"(",
"common",
".",
"TagGRPC",
"(",
"c",
",",
"err",
")",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"}",
"(",
")",
"\n\n",
"// Check if the user is allowed to access this project.",
"allowed",
",",
"err",
":=",
"impl",
".",
"acls",
".",
"IsAllowed",
"(",
"c",
",",
"host",
",",
"project",
")",
"\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"\n",
"case",
"!",
"allowed",
":",
"err",
"=",
"status",
".",
"Errorf",
"(",
"codes",
".",
"NotFound",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Prepare Gitiles client.",
"client",
",",
"err",
":=",
"impl",
".",
"gitilesClient",
"(",
"c",
",",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// Resolve all refs and commits they are pointing at.",
"refTips",
",",
"missingRefs",
",",
"err",
":=",
"gitilesapi",
".",
"NewRefSet",
"(",
"refs",
")",
".",
"Resolve",
"(",
"c",
",",
"client",
",",
"project",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"len",
"(",
"missingRefs",
")",
">",
"0",
"{",
"logging",
".",
"Warningf",
"(",
"c",
",",
"\"",
"\"",
",",
"missingRefs",
")",
"\n",
"}",
"\n\n",
"var",
"logs",
"[",
"]",
"[",
"]",
"*",
"gitpb",
".",
"Commit",
"\n",
"if",
"logs",
",",
"err",
"=",
"impl",
".",
"loadLogsForRefs",
"(",
"c",
",",
"host",
",",
"project",
",",
"excludeRef",
",",
"limit",
",",
"refTips",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// We merge commits from all refs sorted by time into a single list up to a",
"// limit. We use max-heap based merging algorithm below.",
"var",
"h",
"commitHeap",
"\n",
"for",
"_",
",",
"log",
":=",
"range",
"logs",
"{",
"if",
"len",
"(",
"log",
")",
">",
"0",
"{",
"h",
"=",
"append",
"(",
"h",
",",
"refCommits",
"{",
"log",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Keep adding commits to the merged list until we reach the limit or run out",
"// of commits on all refs.",
"heap",
".",
"Init",
"(",
"&",
"h",
")",
"\n",
"commits",
"=",
"make",
"(",
"[",
"]",
"*",
"gitpb",
".",
"Commit",
",",
"0",
",",
"limit",
")",
"\n",
"for",
"len",
"(",
"commits",
")",
"<",
"limit",
"&&",
"len",
"(",
"h",
")",
"!=",
"0",
"{",
"commit",
",",
"empty",
":=",
"h",
"[",
"0",
"]",
".",
"pop",
"(",
")",
"\n",
"// Do not add duplicate commits that come from different refs.",
"if",
"len",
"(",
"commits",
")",
"==",
"0",
"||",
"commits",
"[",
"len",
"(",
"commits",
")",
"-",
"1",
"]",
".",
"Id",
"!=",
"commit",
".",
"Id",
"{",
"commits",
"=",
"append",
"(",
"commits",
",",
"commit",
")",
"\n",
"}",
"\n",
"if",
"empty",
"{",
"heap",
".",
"Remove",
"(",
"&",
"h",
",",
"0",
")",
"\n",
"}",
"else",
"{",
"heap",
".",
"Fix",
"(",
"&",
"h",
",",
"0",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // CombinedLogs implements Client interface. | [
"CombinedLogs",
"implements",
"Client",
"interface",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/milo/git/combined_logs.go#L261-L321 |
9,394 | luci/luci-go | machine-db/appengine/model/racks.go | fetch | func (t *RacksTable) fetch(c context.Context) error {
db := database.Get(c)
rows, err := db.QueryContext(c, `
SELECT id, name, description, state, datacenter_id
FROM racks
`)
if err != nil {
return errors.Annotate(err, "failed to select racks").Err()
}
defer rows.Close()
for rows.Next() {
rack := &Rack{}
if err := rows.Scan(&rack.Id, &rack.Name, &rack.Description, &rack.State, &rack.DatacenterId); err != nil {
return errors.Annotate(err, "failed to scan rack").Err()
}
t.current = append(t.current, rack)
}
return nil
} | go | func (t *RacksTable) fetch(c context.Context) error {
db := database.Get(c)
rows, err := db.QueryContext(c, `
SELECT id, name, description, state, datacenter_id
FROM racks
`)
if err != nil {
return errors.Annotate(err, "failed to select racks").Err()
}
defer rows.Close()
for rows.Next() {
rack := &Rack{}
if err := rows.Scan(&rack.Id, &rack.Name, &rack.Description, &rack.State, &rack.DatacenterId); err != nil {
return errors.Annotate(err, "failed to scan rack").Err()
}
t.current = append(t.current, rack)
}
return nil
} | [
"func",
"(",
"t",
"*",
"RacksTable",
")",
"fetch",
"(",
"c",
"context",
".",
"Context",
")",
"error",
"{",
"db",
":=",
"database",
".",
"Get",
"(",
"c",
")",
"\n",
"rows",
",",
"err",
":=",
"db",
".",
"QueryContext",
"(",
"c",
",",
"`\n\t\tSELECT id, name, description, state, datacenter_id\n\t\tFROM racks\n\t`",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"rack",
":=",
"&",
"Rack",
"{",
"}",
"\n",
"if",
"err",
":=",
"rows",
".",
"Scan",
"(",
"&",
"rack",
".",
"Id",
",",
"&",
"rack",
".",
"Name",
",",
"&",
"rack",
".",
"Description",
",",
"&",
"rack",
".",
"State",
",",
"&",
"rack",
".",
"DatacenterId",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"t",
".",
"current",
"=",
"append",
"(",
"t",
".",
"current",
",",
"rack",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // fetch fetches the racks from the database. | [
"fetch",
"fetches",
"the",
"racks",
"from",
"the",
"database",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/model/racks.go#L50-L68 |
9,395 | luci/luci-go | machine-db/appengine/model/racks.go | remove | func (t *RacksTable) remove(c context.Context) error {
// Avoid using the database connection to prepare unnecessary statements.
if len(t.removals) == 0 {
return nil
}
db := database.Get(c)
stmt, err := db.PrepareContext(c, `
DELETE FROM racks
WHERE id = ?
`)
if err != nil {
return errors.Annotate(err, "failed to prepare statement").Err()
}
defer stmt.Close()
// Remove each rack from the table. It's more efficient to update the slice of
// racks once at the end rather than for each removal, so use a defer.
removed := make(map[int64]struct{}, len(t.removals))
defer func() {
var racks []*Rack
for _, rack := range t.current {
if _, ok := removed[rack.Id]; !ok {
racks = append(racks, rack)
}
}
t.current = racks
}()
for len(t.removals) > 0 {
rack := t.removals[0]
if _, err := stmt.ExecContext(c, rack.Id); err != nil {
// Defer ensures the slice of racks is updated even if we exit early.
return errors.Annotate(err, "failed to remove rack %q", rack.Name).Err()
}
removed[rack.Id] = struct{}{}
t.removals = t.removals[1:]
logging.Infof(c, "Removed rack %q", rack.Name)
}
return nil
} | go | func (t *RacksTable) remove(c context.Context) error {
// Avoid using the database connection to prepare unnecessary statements.
if len(t.removals) == 0 {
return nil
}
db := database.Get(c)
stmt, err := db.PrepareContext(c, `
DELETE FROM racks
WHERE id = ?
`)
if err != nil {
return errors.Annotate(err, "failed to prepare statement").Err()
}
defer stmt.Close()
// Remove each rack from the table. It's more efficient to update the slice of
// racks once at the end rather than for each removal, so use a defer.
removed := make(map[int64]struct{}, len(t.removals))
defer func() {
var racks []*Rack
for _, rack := range t.current {
if _, ok := removed[rack.Id]; !ok {
racks = append(racks, rack)
}
}
t.current = racks
}()
for len(t.removals) > 0 {
rack := t.removals[0]
if _, err := stmt.ExecContext(c, rack.Id); err != nil {
// Defer ensures the slice of racks is updated even if we exit early.
return errors.Annotate(err, "failed to remove rack %q", rack.Name).Err()
}
removed[rack.Id] = struct{}{}
t.removals = t.removals[1:]
logging.Infof(c, "Removed rack %q", rack.Name)
}
return nil
} | [
"func",
"(",
"t",
"*",
"RacksTable",
")",
"remove",
"(",
"c",
"context",
".",
"Context",
")",
"error",
"{",
"// Avoid using the database connection to prepare unnecessary statements.",
"if",
"len",
"(",
"t",
".",
"removals",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"db",
":=",
"database",
".",
"Get",
"(",
"c",
")",
"\n",
"stmt",
",",
"err",
":=",
"db",
".",
"PrepareContext",
"(",
"c",
",",
"`\n\t\tDELETE FROM racks\n\t\tWHERE id = ?\n\t`",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"defer",
"stmt",
".",
"Close",
"(",
")",
"\n\n",
"// Remove each rack from the table. It's more efficient to update the slice of",
"// racks once at the end rather than for each removal, so use a defer.",
"removed",
":=",
"make",
"(",
"map",
"[",
"int64",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"t",
".",
"removals",
")",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"var",
"racks",
"[",
"]",
"*",
"Rack",
"\n",
"for",
"_",
",",
"rack",
":=",
"range",
"t",
".",
"current",
"{",
"if",
"_",
",",
"ok",
":=",
"removed",
"[",
"rack",
".",
"Id",
"]",
";",
"!",
"ok",
"{",
"racks",
"=",
"append",
"(",
"racks",
",",
"rack",
")",
"\n",
"}",
"\n",
"}",
"\n",
"t",
".",
"current",
"=",
"racks",
"\n",
"}",
"(",
")",
"\n",
"for",
"len",
"(",
"t",
".",
"removals",
")",
">",
"0",
"{",
"rack",
":=",
"t",
".",
"removals",
"[",
"0",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"stmt",
".",
"ExecContext",
"(",
"c",
",",
"rack",
".",
"Id",
")",
";",
"err",
"!=",
"nil",
"{",
"// Defer ensures the slice of racks is updated even if we exit early.",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
",",
"rack",
".",
"Name",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"removed",
"[",
"rack",
".",
"Id",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"t",
".",
"removals",
"=",
"t",
".",
"removals",
"[",
"1",
":",
"]",
"\n",
"logging",
".",
"Infof",
"(",
"c",
",",
"\"",
"\"",
",",
"rack",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // remove removes all racks pending removal from the database, clearing pending removals.
// No-op unless computeChanges was called first. Idempotent until computeChanges is called again. | [
"remove",
"removes",
"all",
"racks",
"pending",
"removal",
"from",
"the",
"database",
"clearing",
"pending",
"removals",
".",
"No",
"-",
"op",
"unless",
"computeChanges",
"was",
"called",
"first",
".",
"Idempotent",
"until",
"computeChanges",
"is",
"called",
"again",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/model/racks.go#L161-L200 |
9,396 | luci/luci-go | machine-db/appengine/model/racks.go | ids | func (t *RacksTable) ids(c context.Context) map[string]int64 {
racks := make(map[string]int64, len(t.current))
for _, rack := range t.current {
racks[rack.Name] = rack.Id
}
return racks
} | go | func (t *RacksTable) ids(c context.Context) map[string]int64 {
racks := make(map[string]int64, len(t.current))
for _, rack := range t.current {
racks[rack.Name] = rack.Id
}
return racks
} | [
"func",
"(",
"t",
"*",
"RacksTable",
")",
"ids",
"(",
"c",
"context",
".",
"Context",
")",
"map",
"[",
"string",
"]",
"int64",
"{",
"racks",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int64",
",",
"len",
"(",
"t",
".",
"current",
")",
")",
"\n",
"for",
"_",
",",
"rack",
":=",
"range",
"t",
".",
"current",
"{",
"racks",
"[",
"rack",
".",
"Name",
"]",
"=",
"rack",
".",
"Id",
"\n",
"}",
"\n",
"return",
"racks",
"\n",
"}"
] | // ids returns a map of rack names to IDs. | [
"ids",
"returns",
"a",
"map",
"of",
"rack",
"names",
"to",
"IDs",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/model/racks.go#L246-L252 |
9,397 | luci/luci-go | machine-db/appengine/model/racks.go | EnsureRacks | func EnsureRacks(c context.Context, cfgs []*config.Datacenter, datacenterIds map[string]int64) (map[string]int64, error) {
t := &RacksTable{}
t.datacenters = datacenterIds
if err := t.fetch(c); err != nil {
return nil, errors.Annotate(err, "failed to fetch racks").Err()
}
if err := t.computeChanges(c, cfgs); err != nil {
return nil, errors.Annotate(err, "failed to compute changes").Err()
}
if err := t.add(c); err != nil {
return nil, errors.Annotate(err, "failed to add racks").Err()
}
if err := t.remove(c); err != nil {
return nil, errors.Annotate(err, "failed to remove racks").Err()
}
if err := t.update(c); err != nil {
return nil, errors.Annotate(err, "failed to update racks").Err()
}
return t.ids(c), nil
} | go | func EnsureRacks(c context.Context, cfgs []*config.Datacenter, datacenterIds map[string]int64) (map[string]int64, error) {
t := &RacksTable{}
t.datacenters = datacenterIds
if err := t.fetch(c); err != nil {
return nil, errors.Annotate(err, "failed to fetch racks").Err()
}
if err := t.computeChanges(c, cfgs); err != nil {
return nil, errors.Annotate(err, "failed to compute changes").Err()
}
if err := t.add(c); err != nil {
return nil, errors.Annotate(err, "failed to add racks").Err()
}
if err := t.remove(c); err != nil {
return nil, errors.Annotate(err, "failed to remove racks").Err()
}
if err := t.update(c); err != nil {
return nil, errors.Annotate(err, "failed to update racks").Err()
}
return t.ids(c), nil
} | [
"func",
"EnsureRacks",
"(",
"c",
"context",
".",
"Context",
",",
"cfgs",
"[",
"]",
"*",
"config",
".",
"Datacenter",
",",
"datacenterIds",
"map",
"[",
"string",
"]",
"int64",
")",
"(",
"map",
"[",
"string",
"]",
"int64",
",",
"error",
")",
"{",
"t",
":=",
"&",
"RacksTable",
"{",
"}",
"\n",
"t",
".",
"datacenters",
"=",
"datacenterIds",
"\n",
"if",
"err",
":=",
"t",
".",
"fetch",
"(",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"computeChanges",
"(",
"c",
",",
"cfgs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"add",
"(",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"remove",
"(",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"update",
"(",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n",
"}",
"\n",
"return",
"t",
".",
"ids",
"(",
"c",
")",
",",
"nil",
"\n",
"}"
] | // EnsureRacks ensures the database contains exactly the given racks.
// Returns a map of rack names to IDs in the database. | [
"EnsureRacks",
"ensures",
"the",
"database",
"contains",
"exactly",
"the",
"given",
"racks",
".",
"Returns",
"a",
"map",
"of",
"rack",
"names",
"to",
"IDs",
"in",
"the",
"database",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/machine-db/appengine/model/racks.go#L256-L275 |
9,398 | luci/luci-go | luci_notify/notify/pubsub.go | sortEmailNotify | func sortEmailNotify(en []EmailNotify) {
sort.Slice(en, func(i, j int) bool {
first := en[i]
second := en[j]
emailResult := strings.Compare(first.Email, second.Email)
if emailResult == 0 {
return strings.Compare(first.Template, second.Template) < 0
}
return emailResult < 0
})
} | go | func sortEmailNotify(en []EmailNotify) {
sort.Slice(en, func(i, j int) bool {
first := en[i]
second := en[j]
emailResult := strings.Compare(first.Email, second.Email)
if emailResult == 0 {
return strings.Compare(first.Template, second.Template) < 0
}
return emailResult < 0
})
} | [
"func",
"sortEmailNotify",
"(",
"en",
"[",
"]",
"EmailNotify",
")",
"{",
"sort",
".",
"Slice",
"(",
"en",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"first",
":=",
"en",
"[",
"i",
"]",
"\n",
"second",
":=",
"en",
"[",
"j",
"]",
"\n",
"emailResult",
":=",
"strings",
".",
"Compare",
"(",
"first",
".",
"Email",
",",
"second",
".",
"Email",
")",
"\n",
"if",
"emailResult",
"==",
"0",
"{",
"return",
"strings",
".",
"Compare",
"(",
"first",
".",
"Template",
",",
"second",
".",
"Template",
")",
"<",
"0",
"\n",
"}",
"\n",
"return",
"emailResult",
"<",
"0",
"\n",
"}",
")",
"\n",
"}"
] | // sortEmailNotify sorts a list of EmailNotify by Email, then Template. | [
"sortEmailNotify",
"sorts",
"a",
"list",
"of",
"EmailNotify",
"by",
"Email",
"then",
"Template",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/luci_notify/notify/pubsub.go#L85-L95 |
9,399 | luci/luci-go | luci_notify/notify/pubsub.go | BuildbucketPubSubHandler | func BuildbucketPubSubHandler(ctx *router.Context, d *tq.Dispatcher) error {
c := ctx.Context
build, err := extractBuild(c, ctx.Request)
switch {
case err != nil:
return errors.Annotate(err, "failed to extract build").Err()
case build == nil:
// Ignore.
return nil
default:
return handleBuild(c, d, build, srcmanCheckout, gitilesHistory)
}
} | go | func BuildbucketPubSubHandler(ctx *router.Context, d *tq.Dispatcher) error {
c := ctx.Context
build, err := extractBuild(c, ctx.Request)
switch {
case err != nil:
return errors.Annotate(err, "failed to extract build").Err()
case build == nil:
// Ignore.
return nil
default:
return handleBuild(c, d, build, srcmanCheckout, gitilesHistory)
}
} | [
"func",
"BuildbucketPubSubHandler",
"(",
"ctx",
"*",
"router",
".",
"Context",
",",
"d",
"*",
"tq",
".",
"Dispatcher",
")",
"error",
"{",
"c",
":=",
"ctx",
".",
"Context",
"\n",
"build",
",",
"err",
":=",
"extractBuild",
"(",
"c",
",",
"ctx",
".",
"Request",
")",
"\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
".",
"Err",
"(",
")",
"\n\n",
"case",
"build",
"==",
"nil",
":",
"// Ignore.",
"return",
"nil",
"\n\n",
"default",
":",
"return",
"handleBuild",
"(",
"c",
",",
"d",
",",
"build",
",",
"srcmanCheckout",
",",
"gitilesHistory",
")",
"\n",
"}",
"\n",
"}"
] | // BuildbucketPubSubHandler is the main entrypoint for a new update from buildbucket's pubsub.
//
// This handler delegates the actual processing of the build to handleBuild.
// Its primary purpose is to unwrap context boilerplate and deal with progress-stopping errors. | [
"BuildbucketPubSubHandler",
"is",
"the",
"main",
"entrypoint",
"for",
"a",
"new",
"update",
"from",
"buildbucket",
"s",
"pubsub",
".",
"This",
"handler",
"delegates",
"the",
"actual",
"processing",
"of",
"the",
"build",
"to",
"handleBuild",
".",
"Its",
"primary",
"purpose",
"is",
"to",
"unwrap",
"context",
"boilerplate",
"and",
"deal",
"with",
"progress",
"-",
"stopping",
"errors",
"."
] | f6cef429871eee3be7c6903af88d3ee884eaf683 | https://github.com/luci/luci-go/blob/f6cef429871eee3be7c6903af88d3ee884eaf683/luci_notify/notify/pubsub.go#L344-L358 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.