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
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,400 | fabric8-services/fabric8-wit | space/authz/authz.go | InjectAuthzService | func InjectAuthzService(service AuthzService) goa.Middleware {
return func(h goa.Handler) goa.Handler {
return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
ctxWithAuthzServ := tokencontext.ContextWithSpaceAuthzService(ctx, &AuthzServiceManagerWrapper{Service: service, Config: service.Configuration()})
return h(ctxWithAuthzServ, rw, req)
}
}
} | go | func InjectAuthzService(service AuthzService) goa.Middleware {
return func(h goa.Handler) goa.Handler {
return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
ctxWithAuthzServ := tokencontext.ContextWithSpaceAuthzService(ctx, &AuthzServiceManagerWrapper{Service: service, Config: service.Configuration()})
return h(ctxWithAuthzServ, rw, req)
}
}
} | [
"func",
"InjectAuthzService",
"(",
"service",
"AuthzService",
")",
"goa",
".",
"Middleware",
"{",
"return",
"func",
"(",
"h",
"goa",
".",
"Handler",
")",
"goa",
".",
"Handler",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"rw",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"ctxWithAuthzServ",
":=",
"tokencontext",
".",
"ContextWithSpaceAuthzService",
"(",
"ctx",
",",
"&",
"AuthzServiceManagerWrapper",
"{",
"Service",
":",
"service",
",",
"Config",
":",
"service",
".",
"Configuration",
"(",
")",
"}",
")",
"\n",
"return",
"h",
"(",
"ctxWithAuthzServ",
",",
"rw",
",",
"req",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // InjectAuthzService is a middleware responsible for setting up AuthzService in the context for every request. | [
"InjectAuthzService",
"is",
"a",
"middleware",
"responsible",
"for",
"setting",
"up",
"AuthzService",
"in",
"the",
"context",
"for",
"every",
"request",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/space/authz/authz.go#L139-L146 |
13,401 | fabric8-services/fabric8-wit | space/authz/authz.go | Authorize | func Authorize(ctx context.Context, spaceID string) (bool, error) {
srv := tokencontext.ReadSpaceAuthzServiceFromContext(ctx)
if srv == nil {
log.Error(ctx, map[string]interface{}{
"space_id": spaceID,
}, "Missing space authz service")
return false, errs.New("missing space authz service")
}
manager := srv.(AuthzServiceManager)
return manager.AuthzService().Authorize(ctx, spaceID)
} | go | func Authorize(ctx context.Context, spaceID string) (bool, error) {
srv := tokencontext.ReadSpaceAuthzServiceFromContext(ctx)
if srv == nil {
log.Error(ctx, map[string]interface{}{
"space_id": spaceID,
}, "Missing space authz service")
return false, errs.New("missing space authz service")
}
manager := srv.(AuthzServiceManager)
return manager.AuthzService().Authorize(ctx, spaceID)
} | [
"func",
"Authorize",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"srv",
":=",
"tokencontext",
".",
"ReadSpaceAuthzServiceFromContext",
"(",
"ctx",
")",
"\n",
"if",
"srv",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"spaceID",
",",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"false",
",",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"manager",
":=",
"srv",
".",
"(",
"AuthzServiceManager",
")",
"\n",
"return",
"manager",
".",
"AuthzService",
"(",
")",
".",
"Authorize",
"(",
"ctx",
",",
"spaceID",
")",
"\n",
"}"
] | // Authorize returns true and the corresponding Requesting Party Token if the current user is among the space collaborators | [
"Authorize",
"returns",
"true",
"and",
"the",
"corresponding",
"Requesting",
"Party",
"Token",
"if",
"the",
"current",
"user",
"is",
"among",
"the",
"space",
"collaborators"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/space/authz/authz.go#L149-L160 |
13,402 | fabric8-services/fabric8-wit | goasupport/forward_signer.go | Sign | func (f forwardSigner) Sign(request *http.Request) error {
request.Header.Set("Authorization", "Bearer "+f.token)
return nil
} | go | func (f forwardSigner) Sign(request *http.Request) error {
request.Header.Set("Authorization", "Bearer "+f.token)
return nil
} | [
"func",
"(",
"f",
"forwardSigner",
")",
"Sign",
"(",
"request",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"request",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"f",
".",
"token",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Sign set the Auth header | [
"Sign",
"set",
"the",
"Auth",
"header"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/goasupport/forward_signer.go#L17-L20 |
13,403 | fabric8-services/fabric8-wit | goasupport/forward_signer.go | NewForwardSigner | func NewForwardSigner(ctx context.Context) goaclient.Signer {
token := goajwt.ContextJWT(ctx)
if token == nil {
return nil
}
return &forwardSigner{token: token.Raw}
} | go | func NewForwardSigner(ctx context.Context) goaclient.Signer {
token := goajwt.ContextJWT(ctx)
if token == nil {
return nil
}
return &forwardSigner{token: token.Raw}
} | [
"func",
"NewForwardSigner",
"(",
"ctx",
"context",
".",
"Context",
")",
"goaclient",
".",
"Signer",
"{",
"token",
":=",
"goajwt",
".",
"ContextJWT",
"(",
"ctx",
")",
"\n",
"if",
"token",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"forwardSigner",
"{",
"token",
":",
"token",
".",
"Raw",
"}",
"\n",
"}"
] | // NewForwardSigner return a new signer based on current context | [
"NewForwardSigner",
"return",
"a",
"new",
"signer",
"based",
"on",
"current",
"context"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/goasupport/forward_signer.go#L23-L29 |
13,404 | fabric8-services/fabric8-wit | controller/trackerquery.go | NewTrackerqueryController | func NewTrackerqueryController(service *goa.Service, db application.DB, scheduler *remoteworkitem.Scheduler, configuration trackerQueryConfiguration, authService auth.AuthService) *TrackerqueryController {
return &TrackerqueryController{
Controller: service.NewController("TrackerqueryController"),
db: db,
scheduler: scheduler,
configuration: configuration,
authService: authService,
}
} | go | func NewTrackerqueryController(service *goa.Service, db application.DB, scheduler *remoteworkitem.Scheduler, configuration trackerQueryConfiguration, authService auth.AuthService) *TrackerqueryController {
return &TrackerqueryController{
Controller: service.NewController("TrackerqueryController"),
db: db,
scheduler: scheduler,
configuration: configuration,
authService: authService,
}
} | [
"func",
"NewTrackerqueryController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
",",
"scheduler",
"*",
"remoteworkitem",
".",
"Scheduler",
",",
"configuration",
"trackerQueryConfiguration",
",",
"authService",
"auth",
".",
"AuthService",
")",
"*",
"TrackerqueryController",
"{",
"return",
"&",
"TrackerqueryController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
",",
"scheduler",
":",
"scheduler",
",",
"configuration",
":",
"configuration",
",",
"authService",
":",
"authService",
",",
"}",
"\n",
"}"
] | // NewTrackerqueryController creates a trackerquery controller. | [
"NewTrackerqueryController",
"creates",
"a",
"trackerquery",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/trackerquery.go#L45-L53 |
13,405 | fabric8-services/fabric8-wit | controller/trackerquery.go | ConvertTrackerQueriesToApp | func ConvertTrackerQueriesToApp(appl application.Application, request *http.Request, trackerqueries []remoteworkitem.TrackerQuery) []*app.TrackerQuery {
var ls = []*app.TrackerQuery{}
for _, i := range trackerqueries {
ls = append(ls, convertTrackerQueryToApp(appl, request, i))
}
return ls
} | go | func ConvertTrackerQueriesToApp(appl application.Application, request *http.Request, trackerqueries []remoteworkitem.TrackerQuery) []*app.TrackerQuery {
var ls = []*app.TrackerQuery{}
for _, i := range trackerqueries {
ls = append(ls, convertTrackerQueryToApp(appl, request, i))
}
return ls
} | [
"func",
"ConvertTrackerQueriesToApp",
"(",
"appl",
"application",
".",
"Application",
",",
"request",
"*",
"http",
".",
"Request",
",",
"trackerqueries",
"[",
"]",
"remoteworkitem",
".",
"TrackerQuery",
")",
"[",
"]",
"*",
"app",
".",
"TrackerQuery",
"{",
"var",
"ls",
"=",
"[",
"]",
"*",
"app",
".",
"TrackerQuery",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"trackerqueries",
"{",
"ls",
"=",
"append",
"(",
"ls",
",",
"convertTrackerQueryToApp",
"(",
"appl",
",",
"request",
",",
"i",
")",
")",
"\n",
"}",
"\n",
"return",
"ls",
"\n",
"}"
] | // ConvertTrackerQueriesToApp from internal to external REST representation | [
"ConvertTrackerQueriesToApp",
"from",
"internal",
"to",
"external",
"REST",
"representation"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/trackerquery.go#L217-L223 |
13,406 | fabric8-services/fabric8-wit | controller/trackerquery.go | convertTrackerQueryToApp | func convertTrackerQueryToApp(appl application.Application, request *http.Request, trackerquery remoteworkitem.TrackerQuery) *app.TrackerQuery {
trackerQueryStringType := remoteworkitem.APIStringTypeTrackerQuery
selfURL := rest.AbsoluteURL(request, app.TrackerqueryHref(trackerquery.ID))
t := &app.TrackerQuery{
Type: trackerQueryStringType,
ID: &trackerquery.ID,
Attributes: &app.TrackerQueryAttributes{
Query: trackerquery.Query,
Schedule: trackerquery.Schedule,
},
Links: &app.GenericLinks{
Self: &selfURL,
},
}
return t
} | go | func convertTrackerQueryToApp(appl application.Application, request *http.Request, trackerquery remoteworkitem.TrackerQuery) *app.TrackerQuery {
trackerQueryStringType := remoteworkitem.APIStringTypeTrackerQuery
selfURL := rest.AbsoluteURL(request, app.TrackerqueryHref(trackerquery.ID))
t := &app.TrackerQuery{
Type: trackerQueryStringType,
ID: &trackerquery.ID,
Attributes: &app.TrackerQueryAttributes{
Query: trackerquery.Query,
Schedule: trackerquery.Schedule,
},
Links: &app.GenericLinks{
Self: &selfURL,
},
}
return t
} | [
"func",
"convertTrackerQueryToApp",
"(",
"appl",
"application",
".",
"Application",
",",
"request",
"*",
"http",
".",
"Request",
",",
"trackerquery",
"remoteworkitem",
".",
"TrackerQuery",
")",
"*",
"app",
".",
"TrackerQuery",
"{",
"trackerQueryStringType",
":=",
"remoteworkitem",
".",
"APIStringTypeTrackerQuery",
"\n",
"selfURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"TrackerqueryHref",
"(",
"trackerquery",
".",
"ID",
")",
")",
"\n",
"t",
":=",
"&",
"app",
".",
"TrackerQuery",
"{",
"Type",
":",
"trackerQueryStringType",
",",
"ID",
":",
"&",
"trackerquery",
".",
"ID",
",",
"Attributes",
":",
"&",
"app",
".",
"TrackerQueryAttributes",
"{",
"Query",
":",
"trackerquery",
".",
"Query",
",",
"Schedule",
":",
"trackerquery",
".",
"Schedule",
",",
"}",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"&",
"selfURL",
",",
"}",
",",
"}",
"\n",
"return",
"t",
"\n",
"}"
] | // ConvertTrackerQueryToApp converts from internal to external REST representation | [
"ConvertTrackerQueryToApp",
"converts",
"from",
"internal",
"to",
"external",
"REST",
"representation"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/trackerquery.go#L226-L241 |
13,407 | fabric8-services/fabric8-wit | criteria/expression_substring.go | Substring | func Substring(left Expression, right Expression) Expression {
return reparent(&SubstringExpression{binaryExpression{expression{}, left, right}})
} | go | func Substring(left Expression, right Expression) Expression {
return reparent(&SubstringExpression{binaryExpression{expression{}, left, right}})
} | [
"func",
"Substring",
"(",
"left",
"Expression",
",",
"right",
"Expression",
")",
"Expression",
"{",
"return",
"reparent",
"(",
"&",
"SubstringExpression",
"{",
"binaryExpression",
"{",
"expression",
"{",
"}",
",",
"left",
",",
"right",
"}",
"}",
")",
"\n",
"}"
] | // Substring constructs an SubstringExpression | [
"Substring",
"constructs",
"an",
"SubstringExpression"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/criteria/expression_substring.go#L18-L20 |
13,408 | fabric8-services/fabric8-wit | metric/recorder.go | Recorder | func Recorder() goa.Middleware {
registerMetrics()
return func(h goa.Handler) goa.Handler {
return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
startTime := time.Now()
err := h(ctx, rw, req)
// record metrics
method, entity, code := labelsVal(ctx)
recordReqsTotal(method, entity, code)
recordReqSize(method, entity, code, req)
recordResSize(method, entity, code, goa.ContextResponse(ctx))
recordReqDuration(method, entity, code, startTime)
return err
}
}
} | go | func Recorder() goa.Middleware {
registerMetrics()
return func(h goa.Handler) goa.Handler {
return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error {
startTime := time.Now()
err := h(ctx, rw, req)
// record metrics
method, entity, code := labelsVal(ctx)
recordReqsTotal(method, entity, code)
recordReqSize(method, entity, code, req)
recordResSize(method, entity, code, goa.ContextResponse(ctx))
recordReqDuration(method, entity, code, startTime)
return err
}
}
} | [
"func",
"Recorder",
"(",
")",
"goa",
".",
"Middleware",
"{",
"registerMetrics",
"(",
")",
"\n\n",
"return",
"func",
"(",
"h",
"goa",
".",
"Handler",
")",
"goa",
".",
"Handler",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"rw",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"startTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"err",
":=",
"h",
"(",
"ctx",
",",
"rw",
",",
"req",
")",
"\n\n",
"// record metrics",
"method",
",",
"entity",
",",
"code",
":=",
"labelsVal",
"(",
"ctx",
")",
"\n",
"recordReqsTotal",
"(",
"method",
",",
"entity",
",",
"code",
")",
"\n",
"recordReqSize",
"(",
"method",
",",
"entity",
",",
"code",
",",
"req",
")",
"\n",
"recordResSize",
"(",
"method",
",",
"entity",
",",
"code",
",",
"goa",
".",
"ContextResponse",
"(",
"ctx",
")",
")",
"\n",
"recordReqDuration",
"(",
"method",
",",
"entity",
",",
"code",
",",
"startTime",
")",
"\n\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Recorder record prometheus metrics related to http request and response. | [
"Recorder",
"record",
"prometheus",
"metrics",
"related",
"to",
"http",
"request",
"and",
"response",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/metric/recorder.go#L16-L34 |
13,409 | fabric8-services/fabric8-wit | metric/recorder.go | entityVal | func entityVal(ctrl string) (entity string) {
if strings.HasSuffix(ctrl, "Controller") {
entity = strings.ToLower(strings.TrimSuffix(ctrl, "Controller"))
}
return entity
} | go | func entityVal(ctrl string) (entity string) {
if strings.HasSuffix(ctrl, "Controller") {
entity = strings.ToLower(strings.TrimSuffix(ctrl, "Controller"))
}
return entity
} | [
"func",
"entityVal",
"(",
"ctrl",
"string",
")",
"(",
"entity",
"string",
")",
"{",
"if",
"strings",
".",
"HasSuffix",
"(",
"ctrl",
",",
"\"",
"\"",
")",
"{",
"entity",
"=",
"strings",
".",
"ToLower",
"(",
"strings",
".",
"TrimSuffix",
"(",
"ctrl",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"return",
"entity",
"\n",
"}"
] | // ctrl=SpaceController -> entity=space | [
"ctrl",
"=",
"SpaceController",
"-",
">",
"entity",
"=",
"space"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/metric/recorder.go#L70-L75 |
13,410 | fabric8-services/fabric8-wit | metric/recorder.go | codeVal | func codeVal(status int) string {
code := (status - (status % 100)) / 100
return strconv.Itoa(code) + "xx"
} | go | func codeVal(status int) string {
code := (status - (status % 100)) / 100
return strconv.Itoa(code) + "xx"
} | [
"func",
"codeVal",
"(",
"status",
"int",
")",
"string",
"{",
"code",
":=",
"(",
"status",
"-",
"(",
"status",
"%",
"100",
")",
")",
"/",
"100",
"\n",
"return",
"strconv",
".",
"Itoa",
"(",
"code",
")",
"+",
"\"",
"\"",
"\n",
"}"
] | // Group HTTP status code in the form of 2xx, 3xx etc. | [
"Group",
"HTTP",
"status",
"code",
"in",
"the",
"form",
"of",
"2xx",
"3xx",
"etc",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/metric/recorder.go#L78-L81 |
13,411 | fabric8-services/fabric8-wit | resource/require.go | checkEnvVars | func checkEnvVars(envVars ...string) *string {
var res string
for _, envVar := range envVars {
v, isSet := os.LookupEnv(envVar)
// If we don't explicitly opt out from unit tests
// by specifying F8_RESOURCE_UNIT_TEST=0
// we're going to run them
if !isSet && envVar == UnitTest {
continue
}
// Skip test if environment variable is not set.
if !isSet {
res = fmt.Sprintf(StSkipReasonNotSet, envVar)
return &res
}
// Try to convert to boolean value
isTrue, err := strconv.ParseBool(v)
if err != nil {
res = fmt.Sprintf(StSkipReasonParseError, envVar, v)
return &res
}
if !isTrue {
res = fmt.Sprintf(StSkipReasonValueFalse, envVar, v)
return &res
}
}
return nil
} | go | func checkEnvVars(envVars ...string) *string {
var res string
for _, envVar := range envVars {
v, isSet := os.LookupEnv(envVar)
// If we don't explicitly opt out from unit tests
// by specifying F8_RESOURCE_UNIT_TEST=0
// we're going to run them
if !isSet && envVar == UnitTest {
continue
}
// Skip test if environment variable is not set.
if !isSet {
res = fmt.Sprintf(StSkipReasonNotSet, envVar)
return &res
}
// Try to convert to boolean value
isTrue, err := strconv.ParseBool(v)
if err != nil {
res = fmt.Sprintf(StSkipReasonParseError, envVar, v)
return &res
}
if !isTrue {
res = fmt.Sprintf(StSkipReasonValueFalse, envVar, v)
return &res
}
}
return nil
} | [
"func",
"checkEnvVars",
"(",
"envVars",
"...",
"string",
")",
"*",
"string",
"{",
"var",
"res",
"string",
"\n",
"for",
"_",
",",
"envVar",
":=",
"range",
"envVars",
"{",
"v",
",",
"isSet",
":=",
"os",
".",
"LookupEnv",
"(",
"envVar",
")",
"\n\n",
"// If we don't explicitly opt out from unit tests",
"// by specifying F8_RESOURCE_UNIT_TEST=0",
"// we're going to run them",
"if",
"!",
"isSet",
"&&",
"envVar",
"==",
"UnitTest",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Skip test if environment variable is not set.",
"if",
"!",
"isSet",
"{",
"res",
"=",
"fmt",
".",
"Sprintf",
"(",
"StSkipReasonNotSet",
",",
"envVar",
")",
"\n",
"return",
"&",
"res",
"\n",
"}",
"\n",
"// Try to convert to boolean value",
"isTrue",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"res",
"=",
"fmt",
".",
"Sprintf",
"(",
"StSkipReasonParseError",
",",
"envVar",
",",
"v",
")",
"\n",
"return",
"&",
"res",
"\n",
"}",
"\n\n",
"if",
"!",
"isTrue",
"{",
"res",
"=",
"fmt",
".",
"Sprintf",
"(",
"StSkipReasonValueFalse",
",",
"envVar",
",",
"v",
")",
"\n",
"return",
"&",
"res",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkEnvVars returns a skip reason if one of the given environment variables
// cannot be found or evalutes to false. | [
"checkEnvVars",
"returns",
"a",
"skip",
"reason",
"if",
"one",
"of",
"the",
"given",
"environment",
"variables",
"cannot",
"be",
"found",
"or",
"evalutes",
"to",
"false",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/resource/require.go#L56-L86 |
13,412 | fabric8-services/fabric8-wit | search/search_repository.go | NewGormSearchRepository | func NewGormSearchRepository(db *gorm.DB) *GormSearchRepository {
return &GormSearchRepository{db, workitem.NewWorkItemTypeRepository(db)}
} | go | func NewGormSearchRepository(db *gorm.DB) *GormSearchRepository {
return &GormSearchRepository{db, workitem.NewWorkItemTypeRepository(db)}
} | [
"func",
"NewGormSearchRepository",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"GormSearchRepository",
"{",
"return",
"&",
"GormSearchRepository",
"{",
"db",
",",
"workitem",
".",
"NewWorkItemTypeRepository",
"(",
"db",
")",
"}",
"\n",
"}"
] | // NewGormSearchRepository creates a new search repository | [
"NewGormSearchRepository",
"creates",
"a",
"new",
"search",
"repository"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L57-L59 |
13,413 | fabric8-services/fabric8-wit | search/search_repository.go | RegisterAsKnownURL | func RegisterAsKnownURL(name, urlRegex string) {
compiledRegex := regexp.MustCompile(urlRegex)
groupNames := compiledRegex.SubexpNames()
knownURLLock.Lock()
defer knownURLLock.Unlock()
knownURLs[name] = KnownURL{
URLRegex: urlRegex,
compiledRegex: regexp.MustCompile(urlRegex),
groupNamesInRegex: groupNames,
}
} | go | func RegisterAsKnownURL(name, urlRegex string) {
compiledRegex := regexp.MustCompile(urlRegex)
groupNames := compiledRegex.SubexpNames()
knownURLLock.Lock()
defer knownURLLock.Unlock()
knownURLs[name] = KnownURL{
URLRegex: urlRegex,
compiledRegex: regexp.MustCompile(urlRegex),
groupNamesInRegex: groupNames,
}
} | [
"func",
"RegisterAsKnownURL",
"(",
"name",
",",
"urlRegex",
"string",
")",
"{",
"compiledRegex",
":=",
"regexp",
".",
"MustCompile",
"(",
"urlRegex",
")",
"\n",
"groupNames",
":=",
"compiledRegex",
".",
"SubexpNames",
"(",
")",
"\n",
"knownURLLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"knownURLLock",
".",
"Unlock",
"(",
")",
"\n",
"knownURLs",
"[",
"name",
"]",
"=",
"KnownURL",
"{",
"URLRegex",
":",
"urlRegex",
",",
"compiledRegex",
":",
"regexp",
".",
"MustCompile",
"(",
"urlRegex",
")",
",",
"groupNamesInRegex",
":",
"groupNames",
",",
"}",
"\n",
"}"
] | // RegisterAsKnownURL appends to KnownURLs | [
"RegisterAsKnownURL",
"appends",
"to",
"KnownURLs"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L95-L105 |
13,414 | fabric8-services/fabric8-wit | search/search_repository.go | parseSearchString | func parseSearchString(ctx context.Context, rawSearchString string) (searchKeyword, error) {
// TODO remove special characters and exclaimations if any
rawSearchString = strings.Trim(rawSearchString, "/") // get rid of trailing slashes
rawSearchString = strings.Trim(rawSearchString, "\"")
parts := strings.Fields(rawSearchString)
var res searchKeyword
for _, part := range parts {
// QueryUnescape is required in case of encoded url strings.
// And does not harm regular search strings
// but this processing is required because at this moment, we do not know if
// search input is a regular string or a URL
part, err := url.QueryUnescape(part)
if err != nil {
log.Warn(nil, map[string]interface{}{
"part": part,
}, "unable to escape url!")
}
// IF part is for search with number:1234
// TODO: need to find out the way to use ID fields.
if strings.HasPrefix(part, "number:") {
res.number = append(res.number, strings.TrimPrefix(part, "number:")+":*A")
} else if strings.HasPrefix(part, "type:") {
typeIDStr := strings.TrimPrefix(part, "type:")
if len(typeIDStr) == 0 {
log.Error(ctx, map[string]interface{}{}, "type: part is empty")
return res, errors.NewBadParameterError("Type ID must not be empty", part)
}
typeID, err := uuid.FromString(typeIDStr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"typeID": typeIDStr,
}, "failed to convert type ID string to UUID")
return res, errors.NewBadParameterError("failed to parse type ID string as UUID", typeIDStr)
}
res.workItemTypes = append(res.workItemTypes, typeID)
} else if govalidator.IsURL(part) {
log.Debug(ctx, map[string]interface{}{"url": part}, "found a URL in the query string")
part := strings.ToLower(part)
part = trimProtocolFromURLString(part)
searchQueryFromURL := getSearchQueryFromURLString(part)
log.Debug(ctx, map[string]interface{}{"url": part, "search_query": searchQueryFromURL}, "found a URL in the query string")
res.words = append(res.words, searchQueryFromURL)
} else {
part := strings.ToLower(part)
part = sanitizeURL(part)
res.words = append(res.words, part+":*")
}
}
log.Info(nil, nil, "Search keywords: '%s' -> %v", rawSearchString, res)
return res, nil
} | go | func parseSearchString(ctx context.Context, rawSearchString string) (searchKeyword, error) {
// TODO remove special characters and exclaimations if any
rawSearchString = strings.Trim(rawSearchString, "/") // get rid of trailing slashes
rawSearchString = strings.Trim(rawSearchString, "\"")
parts := strings.Fields(rawSearchString)
var res searchKeyword
for _, part := range parts {
// QueryUnescape is required in case of encoded url strings.
// And does not harm regular search strings
// but this processing is required because at this moment, we do not know if
// search input is a regular string or a URL
part, err := url.QueryUnescape(part)
if err != nil {
log.Warn(nil, map[string]interface{}{
"part": part,
}, "unable to escape url!")
}
// IF part is for search with number:1234
// TODO: need to find out the way to use ID fields.
if strings.HasPrefix(part, "number:") {
res.number = append(res.number, strings.TrimPrefix(part, "number:")+":*A")
} else if strings.HasPrefix(part, "type:") {
typeIDStr := strings.TrimPrefix(part, "type:")
if len(typeIDStr) == 0 {
log.Error(ctx, map[string]interface{}{}, "type: part is empty")
return res, errors.NewBadParameterError("Type ID must not be empty", part)
}
typeID, err := uuid.FromString(typeIDStr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"typeID": typeIDStr,
}, "failed to convert type ID string to UUID")
return res, errors.NewBadParameterError("failed to parse type ID string as UUID", typeIDStr)
}
res.workItemTypes = append(res.workItemTypes, typeID)
} else if govalidator.IsURL(part) {
log.Debug(ctx, map[string]interface{}{"url": part}, "found a URL in the query string")
part := strings.ToLower(part)
part = trimProtocolFromURLString(part)
searchQueryFromURL := getSearchQueryFromURLString(part)
log.Debug(ctx, map[string]interface{}{"url": part, "search_query": searchQueryFromURL}, "found a URL in the query string")
res.words = append(res.words, searchQueryFromURL)
} else {
part := strings.ToLower(part)
part = sanitizeURL(part)
res.words = append(res.words, part+":*")
}
}
log.Info(nil, nil, "Search keywords: '%s' -> %v", rawSearchString, res)
return res, nil
} | [
"func",
"parseSearchString",
"(",
"ctx",
"context",
".",
"Context",
",",
"rawSearchString",
"string",
")",
"(",
"searchKeyword",
",",
"error",
")",
"{",
"// TODO remove special characters and exclaimations if any",
"rawSearchString",
"=",
"strings",
".",
"Trim",
"(",
"rawSearchString",
",",
"\"",
"\"",
")",
"// get rid of trailing slashes",
"\n",
"rawSearchString",
"=",
"strings",
".",
"Trim",
"(",
"rawSearchString",
",",
"\"",
"\\\"",
"\"",
")",
"\n",
"parts",
":=",
"strings",
".",
"Fields",
"(",
"rawSearchString",
")",
"\n",
"var",
"res",
"searchKeyword",
"\n",
"for",
"_",
",",
"part",
":=",
"range",
"parts",
"{",
"// QueryUnescape is required in case of encoded url strings.",
"// And does not harm regular search strings",
"// but this processing is required because at this moment, we do not know if",
"// search input is a regular string or a URL",
"part",
",",
"err",
":=",
"url",
".",
"QueryUnescape",
"(",
"part",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warn",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"part",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// IF part is for search with number:1234",
"// TODO: need to find out the way to use ID fields.",
"if",
"strings",
".",
"HasPrefix",
"(",
"part",
",",
"\"",
"\"",
")",
"{",
"res",
".",
"number",
"=",
"append",
"(",
"res",
".",
"number",
",",
"strings",
".",
"TrimPrefix",
"(",
"part",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"strings",
".",
"HasPrefix",
"(",
"part",
",",
"\"",
"\"",
")",
"{",
"typeIDStr",
":=",
"strings",
".",
"TrimPrefix",
"(",
"part",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"typeIDStr",
")",
"==",
"0",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"res",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"part",
")",
"\n",
"}",
"\n",
"typeID",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"typeIDStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"typeIDStr",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"res",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"typeIDStr",
")",
"\n",
"}",
"\n",
"res",
".",
"workItemTypes",
"=",
"append",
"(",
"res",
".",
"workItemTypes",
",",
"typeID",
")",
"\n",
"}",
"else",
"if",
"govalidator",
".",
"IsURL",
"(",
"part",
")",
"{",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"part",
"}",
",",
"\"",
"\"",
")",
"\n",
"part",
":=",
"strings",
".",
"ToLower",
"(",
"part",
")",
"\n",
"part",
"=",
"trimProtocolFromURLString",
"(",
"part",
")",
"\n",
"searchQueryFromURL",
":=",
"getSearchQueryFromURLString",
"(",
"part",
")",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"part",
",",
"\"",
"\"",
":",
"searchQueryFromURL",
"}",
",",
"\"",
"\"",
")",
"\n",
"res",
".",
"words",
"=",
"append",
"(",
"res",
".",
"words",
",",
"searchQueryFromURL",
")",
"\n",
"}",
"else",
"{",
"part",
":=",
"strings",
".",
"ToLower",
"(",
"part",
")",
"\n",
"part",
"=",
"sanitizeURL",
"(",
"part",
")",
"\n",
"res",
".",
"words",
"=",
"append",
"(",
"res",
".",
"words",
",",
"part",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"log",
".",
"Info",
"(",
"nil",
",",
"nil",
",",
"\"",
"\"",
",",
"rawSearchString",
",",
"res",
")",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // parseSearchString accepts a raw string and generates a searchKeyword object | [
"parseSearchString",
"accepts",
"a",
"raw",
"string",
"and",
"generates",
"a",
"searchKeyword",
"object"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L216-L268 |
13,415 | fabric8-services/fabric8-wit | search/search_repository.go | ParseFilterString | func ParseFilterString(ctx context.Context, rawSearchString string) (criteria.Expression, *QueryOptions, error) {
fm := map[string]interface{}{}
// Parsing/Unmarshalling JSON encoding/json
err := json.Unmarshal([]byte(rawSearchString), &fm)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"rawSearchString": rawSearchString,
}, "failed to unmarshal raw search string")
return nil, nil, errors.NewBadParameterError("expression", rawSearchString+": "+err.Error())
}
q := Query{}
parseMap(fm, &q)
q.Options = parseOptions(fm)
exp, err := q.generateExpression()
return exp, q.Options, err
} | go | func ParseFilterString(ctx context.Context, rawSearchString string) (criteria.Expression, *QueryOptions, error) {
fm := map[string]interface{}{}
// Parsing/Unmarshalling JSON encoding/json
err := json.Unmarshal([]byte(rawSearchString), &fm)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"rawSearchString": rawSearchString,
}, "failed to unmarshal raw search string")
return nil, nil, errors.NewBadParameterError("expression", rawSearchString+": "+err.Error())
}
q := Query{}
parseMap(fm, &q)
q.Options = parseOptions(fm)
exp, err := q.generateExpression()
return exp, q.Options, err
} | [
"func",
"ParseFilterString",
"(",
"ctx",
"context",
".",
"Context",
",",
"rawSearchString",
"string",
")",
"(",
"criteria",
".",
"Expression",
",",
"*",
"QueryOptions",
",",
"error",
")",
"{",
"fm",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"// Parsing/Unmarshalling JSON encoding/json",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"rawSearchString",
")",
",",
"&",
"fm",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"rawSearchString",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"rawSearchString",
"+",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"q",
":=",
"Query",
"{",
"}",
"\n",
"parseMap",
"(",
"fm",
",",
"&",
"q",
")",
"\n\n",
"q",
".",
"Options",
"=",
"parseOptions",
"(",
"fm",
")",
"\n\n",
"exp",
",",
"err",
":=",
"q",
".",
"generateExpression",
"(",
")",
"\n",
"return",
"exp",
",",
"q",
".",
"Options",
",",
"err",
"\n",
"}"
] | // ParseFilterString accepts a raw string and generates a criteria expression | [
"ParseFilterString",
"accepts",
"a",
"raw",
"string",
"and",
"generates",
"a",
"criteria",
"expression"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L545-L564 |
13,416 | fabric8-services/fabric8-wit | search/search_repository.go | generateSQLSearchInfo | func generateSQLSearchInfo(keywords searchKeyword) (sqlParameter string) {
numberStr := strings.Join(keywords.number, " & ")
wordStr := strings.Join(keywords.words, " & ")
var fragments []string
for _, v := range []string{numberStr, wordStr} {
if v != "" {
fragments = append(fragments, v)
}
}
searchStr := strings.Join(fragments, " & ")
return searchStr
} | go | func generateSQLSearchInfo(keywords searchKeyword) (sqlParameter string) {
numberStr := strings.Join(keywords.number, " & ")
wordStr := strings.Join(keywords.words, " & ")
var fragments []string
for _, v := range []string{numberStr, wordStr} {
if v != "" {
fragments = append(fragments, v)
}
}
searchStr := strings.Join(fragments, " & ")
return searchStr
} | [
"func",
"generateSQLSearchInfo",
"(",
"keywords",
"searchKeyword",
")",
"(",
"sqlParameter",
"string",
")",
"{",
"numberStr",
":=",
"strings",
".",
"Join",
"(",
"keywords",
".",
"number",
",",
"\"",
"\"",
")",
"\n",
"wordStr",
":=",
"strings",
".",
"Join",
"(",
"keywords",
".",
"words",
",",
"\"",
"\"",
")",
"\n",
"var",
"fragments",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"[",
"]",
"string",
"{",
"numberStr",
",",
"wordStr",
"}",
"{",
"if",
"v",
"!=",
"\"",
"\"",
"{",
"fragments",
"=",
"append",
"(",
"fragments",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"searchStr",
":=",
"strings",
".",
"Join",
"(",
"fragments",
",",
"\"",
"\"",
")",
"\n",
"return",
"searchStr",
"\n",
"}"
] | // generateSQLSearchInfo accepts searchKeyword and join them in a way that can be used in sql | [
"generateSQLSearchInfo",
"accepts",
"searchKeyword",
"and",
"join",
"them",
"in",
"a",
"way",
"that",
"can",
"be",
"used",
"in",
"sql"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L567-L578 |
13,417 | fabric8-services/fabric8-wit | search/search_repository.go | SearchFullText | func (r *GormSearchRepository) SearchFullText(ctx context.Context, rawSearchString string, start *int, limit *int, spaceID *string) ([]workitem.WorkItem, int, error) {
// parse
// generateSearchQuery
// ....
parsedSearchDict, err := parseSearchString(ctx, rawSearchString)
if err != nil {
return nil, 0, errs.WithStack(err)
}
sqlSearchQueryParameter := generateSQLSearchInfo(parsedSearchDict)
var rows []workitem.WorkItemStorage
log.Debug(ctx, map[string]interface{}{"search query": sqlSearchQueryParameter}, "searching for work items")
rows, count, err := r.search(ctx, sqlSearchQueryParameter, parsedSearchDict.workItemTypes, start, limit, spaceID)
if err != nil {
return nil, 0, errs.WithStack(err)
}
result := make([]workitem.WorkItem, len(rows))
for index, value := range rows {
var err error
// FIXME: Against best practice http://go-database-sql.org/retrieving.html
wiType, err := r.witr.Load(ctx, value.Type)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"wit": value.Type,
}, "failed to load work item type")
spew.Dump(value)
return nil, 0, errors.NewInternalError(ctx, errs.Wrap(err, "failed to load work item type"))
}
wiModel, err := workitem.ConvertWorkItemStorageToModel(wiType, &value)
if err != nil {
return nil, 0, errors.NewConversionError(err.Error())
}
result[index] = *wiModel
}
return result, count, nil
} | go | func (r *GormSearchRepository) SearchFullText(ctx context.Context, rawSearchString string, start *int, limit *int, spaceID *string) ([]workitem.WorkItem, int, error) {
// parse
// generateSearchQuery
// ....
parsedSearchDict, err := parseSearchString(ctx, rawSearchString)
if err != nil {
return nil, 0, errs.WithStack(err)
}
sqlSearchQueryParameter := generateSQLSearchInfo(parsedSearchDict)
var rows []workitem.WorkItemStorage
log.Debug(ctx, map[string]interface{}{"search query": sqlSearchQueryParameter}, "searching for work items")
rows, count, err := r.search(ctx, sqlSearchQueryParameter, parsedSearchDict.workItemTypes, start, limit, spaceID)
if err != nil {
return nil, 0, errs.WithStack(err)
}
result := make([]workitem.WorkItem, len(rows))
for index, value := range rows {
var err error
// FIXME: Against best practice http://go-database-sql.org/retrieving.html
wiType, err := r.witr.Load(ctx, value.Type)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"wit": value.Type,
}, "failed to load work item type")
spew.Dump(value)
return nil, 0, errors.NewInternalError(ctx, errs.Wrap(err, "failed to load work item type"))
}
wiModel, err := workitem.ConvertWorkItemStorageToModel(wiType, &value)
if err != nil {
return nil, 0, errors.NewConversionError(err.Error())
}
result[index] = *wiModel
}
return result, count, nil
} | [
"func",
"(",
"r",
"*",
"GormSearchRepository",
")",
"SearchFullText",
"(",
"ctx",
"context",
".",
"Context",
",",
"rawSearchString",
"string",
",",
"start",
"*",
"int",
",",
"limit",
"*",
"int",
",",
"spaceID",
"*",
"string",
")",
"(",
"[",
"]",
"workitem",
".",
"WorkItem",
",",
"int",
",",
"error",
")",
"{",
"// parse",
"// generateSearchQuery",
"// ....",
"parsedSearchDict",
",",
"err",
":=",
"parseSearchString",
"(",
"ctx",
",",
"rawSearchString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"sqlSearchQueryParameter",
":=",
"generateSQLSearchInfo",
"(",
"parsedSearchDict",
")",
"\n",
"var",
"rows",
"[",
"]",
"workitem",
".",
"WorkItemStorage",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"sqlSearchQueryParameter",
"}",
",",
"\"",
"\"",
")",
"\n",
"rows",
",",
"count",
",",
"err",
":=",
"r",
".",
"search",
"(",
"ctx",
",",
"sqlSearchQueryParameter",
",",
"parsedSearchDict",
".",
"workItemTypes",
",",
"start",
",",
"limit",
",",
"spaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"result",
":=",
"make",
"(",
"[",
"]",
"workitem",
".",
"WorkItem",
",",
"len",
"(",
"rows",
")",
")",
"\n\n",
"for",
"index",
",",
"value",
":=",
"range",
"rows",
"{",
"var",
"err",
"error",
"\n",
"// FIXME: Against best practice http://go-database-sql.org/retrieving.html",
"wiType",
",",
"err",
":=",
"r",
".",
"witr",
".",
"Load",
"(",
"ctx",
",",
"value",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"value",
".",
"Type",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"spew",
".",
"Dump",
"(",
"value",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"wiModel",
",",
"err",
":=",
"workitem",
".",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"&",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"errors",
".",
"NewConversionError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"result",
"[",
"index",
"]",
"=",
"*",
"wiModel",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"count",
",",
"nil",
"\n",
"}"
] | // SearchFullText Search returns work items for the given query | [
"SearchFullText",
"Search",
"returns",
"work",
"items",
"for",
"the",
"given",
"query"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/search/search_repository.go#L663-L701 |
13,418 | fabric8-services/fabric8-wit | tool/wit-cli/main.go | newJWTSigner | func newJWTSigner(key, format string) goaclient.Signer {
return &goaclient.APIKeySigner{
SignQuery: false,
KeyName: "Authorization",
KeyValue: key,
Format: format,
}
} | go | func newJWTSigner(key, format string) goaclient.Signer {
return &goaclient.APIKeySigner{
SignQuery: false,
KeyName: "Authorization",
KeyValue: key,
Format: format,
}
} | [
"func",
"newJWTSigner",
"(",
"key",
",",
"format",
"string",
")",
"goaclient",
".",
"Signer",
"{",
"return",
"&",
"goaclient",
".",
"APIKeySigner",
"{",
"SignQuery",
":",
"false",
",",
"KeyName",
":",
"\"",
"\"",
",",
"KeyValue",
":",
"key",
",",
"Format",
":",
"format",
",",
"}",
"\n\n",
"}"
] | // newJWTSigner returns the request signer used for authenticating
// against the jwt security scheme. | [
"newJWTSigner",
"returns",
"the",
"request",
"signer",
"used",
"for",
"authenticating",
"against",
"the",
"jwt",
"security",
"scheme",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/tool/wit-cli/main.go#L64-L72 |
13,419 | fabric8-services/fabric8-wit | criteria/criteria.go | IterateParents | func IterateParents(exp Expression, f func(Expression) bool) {
if exp != nil {
exp = exp.Parent()
}
for exp != nil {
if !f(exp) {
return
}
exp = exp.Parent()
}
} | go | func IterateParents(exp Expression, f func(Expression) bool) {
if exp != nil {
exp = exp.Parent()
}
for exp != nil {
if !f(exp) {
return
}
exp = exp.Parent()
}
} | [
"func",
"IterateParents",
"(",
"exp",
"Expression",
",",
"f",
"func",
"(",
"Expression",
")",
"bool",
")",
"{",
"if",
"exp",
"!=",
"nil",
"{",
"exp",
"=",
"exp",
".",
"Parent",
"(",
")",
"\n",
"}",
"\n",
"for",
"exp",
"!=",
"nil",
"{",
"if",
"!",
"f",
"(",
"exp",
")",
"{",
"return",
"\n",
"}",
"\n",
"exp",
"=",
"exp",
".",
"Parent",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // IterateParents calls f for every member of the parent chain
// Stops iterating if f returns false | [
"IterateParents",
"calls",
"f",
"for",
"every",
"member",
"of",
"the",
"parent",
"chain",
"Stops",
"iterating",
"if",
"f",
"returns",
"false"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/criteria/criteria.go#L5-L15 |
13,420 | fabric8-services/fabric8-wit | controller/permission.go | CRUDWorkItem | func (p *PermissionDefinition) CRUDWorkItem() []string {
return []string{p.CreateWorkItem, p.ReadWorkItem, p.UpdateWorkItem, p.DeleteWorkItem}
} | go | func (p *PermissionDefinition) CRUDWorkItem() []string {
return []string{p.CreateWorkItem, p.ReadWorkItem, p.UpdateWorkItem, p.DeleteWorkItem}
} | [
"func",
"(",
"p",
"*",
"PermissionDefinition",
")",
"CRUDWorkItem",
"(",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"p",
".",
"CreateWorkItem",
",",
"p",
".",
"ReadWorkItem",
",",
"p",
".",
"UpdateWorkItem",
",",
"p",
".",
"DeleteWorkItem",
"}",
"\n",
"}"
] | // CRUDWorkItem returns all CRUD permissions for a WorkItem | [
"CRUDWorkItem",
"returns",
"all",
"CRUD",
"permissions",
"for",
"a",
"WorkItem"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/permission.go#L12-L14 |
13,421 | fabric8-services/fabric8-wit | criteria/expression_and.go | And | func And(left Expression, right Expression) Expression {
return reparent(&AndExpression{binaryExpression{expression{}, left, right}})
} | go | func And(left Expression, right Expression) Expression {
return reparent(&AndExpression{binaryExpression{expression{}, left, right}})
} | [
"func",
"And",
"(",
"left",
"Expression",
",",
"right",
"Expression",
")",
"Expression",
"{",
"return",
"reparent",
"(",
"&",
"AndExpression",
"{",
"binaryExpression",
"{",
"expression",
"{",
"}",
",",
"left",
",",
"right",
"}",
"}",
")",
"\n",
"}"
] | // And constructs an AndExpression | [
"And",
"constructs",
"an",
"AndExpression"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/criteria/expression_and.go#L18-L20 |
13,422 | fabric8-services/fabric8-wit | rendering/markdown.go | MarkdownCommonHighlighter | func MarkdownCommonHighlighter(input []byte) []byte {
renderer := highlightHTMLRenderer{blackfriday.HtmlRenderer(commonHTMLFlags, "", ""), 0}
return blackfriday.MarkdownOptions(input, &renderer, blackfriday.Options{
Extensions: commonExtensions})
} | go | func MarkdownCommonHighlighter(input []byte) []byte {
renderer := highlightHTMLRenderer{blackfriday.HtmlRenderer(commonHTMLFlags, "", ""), 0}
return blackfriday.MarkdownOptions(input, &renderer, blackfriday.Options{
Extensions: commonExtensions})
} | [
"func",
"MarkdownCommonHighlighter",
"(",
"input",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"renderer",
":=",
"highlightHTMLRenderer",
"{",
"blackfriday",
".",
"HtmlRenderer",
"(",
"commonHTMLFlags",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"0",
"}",
"\n",
"return",
"blackfriday",
".",
"MarkdownOptions",
"(",
"input",
",",
"&",
"renderer",
",",
"blackfriday",
".",
"Options",
"{",
"Extensions",
":",
"commonExtensions",
"}",
")",
"\n",
"}"
] | // MarkdownCommonHighlighter uses the blackfriday.MarkdownCommon setup but also includes
// code-prettify formatting of BlockCode segments | [
"MarkdownCommonHighlighter",
"uses",
"the",
"blackfriday",
".",
"MarkdownCommon",
"setup",
"but",
"also",
"includes",
"code",
"-",
"prettify",
"formatting",
"of",
"BlockCode",
"segments"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/rendering/markdown.go#L36-L40 |
13,423 | fabric8-services/fabric8-wit | rendering/markdown.go | ListItem | func (h *highlightHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
text = append([]byte(fmt.Sprintf(`<input class="markdown-checkbox" type="checkbox" disabled="disabled" data-checkbox-index="%d"></input>`, h.checkboxIndex)), text[4:]...)
h.checkboxIndex++
case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
text = append([]byte(fmt.Sprintf(`<input class="markdown-checkbox" type="checkbox" disabled="disabled" checked="" data-checkbox-index="%d"></input>`, h.checkboxIndex)), text[4:]...)
h.checkboxIndex++
}
h.Renderer.ListItem(out, text, flags)
} | go | func (h *highlightHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
text = append([]byte(fmt.Sprintf(`<input class="markdown-checkbox" type="checkbox" disabled="disabled" data-checkbox-index="%d"></input>`, h.checkboxIndex)), text[4:]...)
h.checkboxIndex++
case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
text = append([]byte(fmt.Sprintf(`<input class="markdown-checkbox" type="checkbox" disabled="disabled" checked="" data-checkbox-index="%d"></input>`, h.checkboxIndex)), text[4:]...)
h.checkboxIndex++
}
h.Renderer.ListItem(out, text, flags)
} | [
"func",
"(",
"h",
"*",
"highlightHTMLRenderer",
")",
"ListItem",
"(",
"out",
"*",
"bytes",
".",
"Buffer",
",",
"text",
"[",
"]",
"byte",
",",
"flags",
"int",
")",
"{",
"switch",
"{",
"case",
"bytes",
".",
"HasPrefix",
"(",
"text",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
":",
"text",
"=",
"append",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`<input class=\"markdown-checkbox\" type=\"checkbox\" disabled=\"disabled\" data-checkbox-index=\"%d\"></input>`",
",",
"h",
".",
"checkboxIndex",
")",
")",
",",
"text",
"[",
"4",
":",
"]",
"...",
")",
"\n",
"h",
".",
"checkboxIndex",
"++",
"\n",
"case",
"bytes",
".",
"HasPrefix",
"(",
"text",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"||",
"bytes",
".",
"HasPrefix",
"(",
"text",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
":",
"text",
"=",
"append",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`<input class=\"markdown-checkbox\" type=\"checkbox\" disabled=\"disabled\" checked=\"\" data-checkbox-index=\"%d\"></input>`",
",",
"h",
".",
"checkboxIndex",
")",
")",
",",
"text",
"[",
"4",
":",
"]",
"...",
")",
"\n",
"h",
".",
"checkboxIndex",
"++",
"\n",
"}",
"\n",
"h",
".",
"Renderer",
".",
"ListItem",
"(",
"out",
",",
"text",
",",
"flags",
")",
"\n",
"}"
] | // ListItem overrides the default ListItem render and adds support for GH-style
// checkboxes on service side. For the contents of the list item beyond the
// checkbox prefix, the default Html.ListItem is called.
// This adds a data-checkbox-index attribute that contains the ordinal of the
// checkbox in the rendered Markdown. This can be used by the ui to find the
// reference to the original Markdown code from a rendered HTML. | [
"ListItem",
"overrides",
"the",
"default",
"ListItem",
"render",
"and",
"adds",
"support",
"for",
"GH",
"-",
"style",
"checkboxes",
"on",
"service",
"side",
".",
"For",
"the",
"contents",
"of",
"the",
"list",
"item",
"beyond",
"the",
"checkbox",
"prefix",
"the",
"default",
"Html",
".",
"ListItem",
"is",
"called",
".",
"This",
"adds",
"a",
"data",
"-",
"checkbox",
"-",
"index",
"attribute",
"that",
"contains",
"the",
"ordinal",
"of",
"the",
"checkbox",
"in",
"the",
"rendered",
"Markdown",
".",
"This",
"can",
"be",
"used",
"by",
"the",
"ui",
"to",
"find",
"the",
"reference",
"to",
"the",
"original",
"Markdown",
"code",
"from",
"a",
"rendered",
"HTML",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/rendering/markdown.go#L53-L63 |
13,424 | fabric8-services/fabric8-wit | rendering/markdown.go | BlockCode | func (h highlightHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
highlighted, err := syntaxhighlight.AsHTML(text)
if err != nil {
h.Renderer.BlockCode(out, text, lang)
} else {
if out.Len() > 0 {
out.WriteByte('\n')
}
// parse out the language names/classes
count := 0
for _, elt := range strings.Fields(lang) {
if elt[0] == '.' {
elt = elt[1:]
}
if len(elt) == 0 {
continue
}
if count == 0 {
out.WriteString("<pre><code class=\"prettyprint language-")
} else {
out.WriteByte(' ')
}
out.Write([]byte(elt)) // attrEscape(out, []byte(elt))
count++
}
if count == 0 {
out.WriteString("<pre><code class=\"prettyprint\">")
} else {
out.WriteString("\">")
}
out.Write(highlighted)
out.WriteString("</code></pre>\n")
}
} | go | func (h highlightHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
highlighted, err := syntaxhighlight.AsHTML(text)
if err != nil {
h.Renderer.BlockCode(out, text, lang)
} else {
if out.Len() > 0 {
out.WriteByte('\n')
}
// parse out the language names/classes
count := 0
for _, elt := range strings.Fields(lang) {
if elt[0] == '.' {
elt = elt[1:]
}
if len(elt) == 0 {
continue
}
if count == 0 {
out.WriteString("<pre><code class=\"prettyprint language-")
} else {
out.WriteByte(' ')
}
out.Write([]byte(elt)) // attrEscape(out, []byte(elt))
count++
}
if count == 0 {
out.WriteString("<pre><code class=\"prettyprint\">")
} else {
out.WriteString("\">")
}
out.Write(highlighted)
out.WriteString("</code></pre>\n")
}
} | [
"func",
"(",
"h",
"highlightHTMLRenderer",
")",
"BlockCode",
"(",
"out",
"*",
"bytes",
".",
"Buffer",
",",
"text",
"[",
"]",
"byte",
",",
"lang",
"string",
")",
"{",
"highlighted",
",",
"err",
":=",
"syntaxhighlight",
".",
"AsHTML",
"(",
"text",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"h",
".",
"Renderer",
".",
"BlockCode",
"(",
"out",
",",
"text",
",",
"lang",
")",
"\n",
"}",
"else",
"{",
"if",
"out",
".",
"Len",
"(",
")",
">",
"0",
"{",
"out",
".",
"WriteByte",
"(",
"'\\n'",
")",
"\n",
"}",
"\n\n",
"// parse out the language names/classes",
"count",
":=",
"0",
"\n",
"for",
"_",
",",
"elt",
":=",
"range",
"strings",
".",
"Fields",
"(",
"lang",
")",
"{",
"if",
"elt",
"[",
"0",
"]",
"==",
"'.'",
"{",
"elt",
"=",
"elt",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"if",
"len",
"(",
"elt",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"count",
"==",
"0",
"{",
"out",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"out",
".",
"WriteByte",
"(",
"' '",
")",
"\n",
"}",
"\n",
"out",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"elt",
")",
")",
"// attrEscape(out, []byte(elt))",
"\n",
"count",
"++",
"\n",
"}",
"\n\n",
"if",
"count",
"==",
"0",
"{",
"out",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"out",
".",
"WriteString",
"(",
"\"",
"\\\"",
"\"",
")",
"\n",
"}",
"\n\n",
"out",
".",
"Write",
"(",
"highlighted",
")",
"\n",
"out",
".",
"WriteString",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // BlackCode overrides the standard Html Renderer to add support for prettify of source code within block
// If highlighter fail, normal Html.BlockCode is called | [
"BlackCode",
"overrides",
"the",
"standard",
"Html",
"Renderer",
"to",
"add",
"support",
"for",
"prettify",
"of",
"source",
"code",
"within",
"block",
"If",
"highlighter",
"fail",
"normal",
"Html",
".",
"BlockCode",
"is",
"called"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/rendering/markdown.go#L67-L104 |
13,425 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | ParseSortWorkItemsBy | func ParseSortWorkItemsBy(s *string) (SortWorkItemsBy, error) {
if s == nil {
// this is the default case
// which returns workitems with highest execution order
return SortWorkItemsByDefault, nil
}
var sort SortWorkItemsBy
switch *s {
case "execution":
sort = SortWorkItemsByExecutionAsc
case "-execution":
sort = SortWorkItemsByExecutionDesc
case "created":
sort = SortWorkItemsByCreatedAtAsc
case "-created":
sort = SortWorkItemsByCreatedAtDesc
case "updated":
sort = SortWorkItemsByUpdatedAtAsc
case "-updated":
sort = SortWorkItemsByUpdatedAtDesc
default:
return SortWorkItemsBy(""), errors.NewBadParameterError("sort", *s)
}
return sort, nil
} | go | func ParseSortWorkItemsBy(s *string) (SortWorkItemsBy, error) {
if s == nil {
// this is the default case
// which returns workitems with highest execution order
return SortWorkItemsByDefault, nil
}
var sort SortWorkItemsBy
switch *s {
case "execution":
sort = SortWorkItemsByExecutionAsc
case "-execution":
sort = SortWorkItemsByExecutionDesc
case "created":
sort = SortWorkItemsByCreatedAtAsc
case "-created":
sort = SortWorkItemsByCreatedAtDesc
case "updated":
sort = SortWorkItemsByUpdatedAtAsc
case "-updated":
sort = SortWorkItemsByUpdatedAtDesc
default:
return SortWorkItemsBy(""), errors.NewBadParameterError("sort", *s)
}
return sort, nil
} | [
"func",
"ParseSortWorkItemsBy",
"(",
"s",
"*",
"string",
")",
"(",
"SortWorkItemsBy",
",",
"error",
")",
"{",
"if",
"s",
"==",
"nil",
"{",
"// this is the default case",
"// which returns workitems with highest execution order",
"return",
"SortWorkItemsByDefault",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"sort",
"SortWorkItemsBy",
"\n",
"switch",
"*",
"s",
"{",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByExecutionAsc",
"\n",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByExecutionDesc",
"\n",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByCreatedAtAsc",
"\n",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByCreatedAtDesc",
"\n",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByUpdatedAtAsc",
"\n",
"case",
"\"",
"\"",
":",
"sort",
"=",
"SortWorkItemsByUpdatedAtDesc",
"\n",
"default",
":",
"return",
"SortWorkItemsBy",
"(",
"\"",
"\"",
")",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"*",
"s",
")",
"\n",
"}",
"\n",
"return",
"sort",
",",
"nil",
"\n",
"}"
] | // ParseSortWorkItemsBy parses the string input and returns object of type SortWorkItemsBy
// which can directly be used while querying database to order the output. | [
"ParseSortWorkItemsBy",
"parses",
"the",
"string",
"input",
"and",
"returns",
"object",
"of",
"type",
"SortWorkItemsBy",
"which",
"can",
"directly",
"be",
"used",
"while",
"querying",
"database",
"to",
"order",
"the",
"output",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L62-L87 |
13,426 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | NewWorkItemRepository | func NewWorkItemRepository(db *gorm.DB) *GormWorkItemRepository {
repository := &GormWorkItemRepository{
db: db,
winr: numbersequence.NewWorkItemNumberSequenceRepository(db),
witr: &GormWorkItemTypeRepository{db},
wirr: &GormRevisionRepository{db},
space: space.NewRepository(db),
}
return repository
} | go | func NewWorkItemRepository(db *gorm.DB) *GormWorkItemRepository {
repository := &GormWorkItemRepository{
db: db,
winr: numbersequence.NewWorkItemNumberSequenceRepository(db),
witr: &GormWorkItemTypeRepository{db},
wirr: &GormRevisionRepository{db},
space: space.NewRepository(db),
}
return repository
} | [
"func",
"NewWorkItemRepository",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"GormWorkItemRepository",
"{",
"repository",
":=",
"&",
"GormWorkItemRepository",
"{",
"db",
":",
"db",
",",
"winr",
":",
"numbersequence",
".",
"NewWorkItemNumberSequenceRepository",
"(",
"db",
")",
",",
"witr",
":",
"&",
"GormWorkItemTypeRepository",
"{",
"db",
"}",
",",
"wirr",
":",
"&",
"GormRevisionRepository",
"{",
"db",
"}",
",",
"space",
":",
"space",
".",
"NewRepository",
"(",
"db",
")",
",",
"}",
"\n",
"return",
"repository",
"\n",
"}"
] | // NewWorkItemRepository creates a GormWorkItemRepository | [
"NewWorkItemRepository",
"creates",
"a",
"GormWorkItemRepository"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L110-L119 |
13,427 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadBatchFromDB | func (r *GormWorkItemRepository) LoadBatchFromDB(ctx context.Context, ids []uuid.UUID) ([]WorkItemStorage, error) {
log.Info(nil, map[string]interface{}{
"wi_ids": ids,
}, "Loading work items")
res := []WorkItemStorage{}
tx := r.db.Model(WorkItemStorage{}).Where("id IN (?)", ids).Find(&res)
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
return res, nil
} | go | func (r *GormWorkItemRepository) LoadBatchFromDB(ctx context.Context, ids []uuid.UUID) ([]WorkItemStorage, error) {
log.Info(nil, map[string]interface{}{
"wi_ids": ids,
}, "Loading work items")
res := []WorkItemStorage{}
tx := r.db.Model(WorkItemStorage{}).Where("id IN (?)", ids).Find(&res)
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
return res, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadBatchFromDB",
"(",
"ctx",
"context",
".",
"Context",
",",
"ids",
"[",
"]",
"uuid",
".",
"UUID",
")",
"(",
"[",
"]",
"WorkItemStorage",
",",
"error",
")",
"{",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ids",
",",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"res",
":=",
"[",
"]",
"WorkItemStorage",
"{",
"}",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"WorkItemStorage",
"{",
"}",
")",
".",
"Where",
"(",
"\"",
"\"",
",",
"ids",
")",
".",
"Find",
"(",
"&",
"res",
")",
"\n",
"if",
"tx",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"tx",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // LoadBatchFromDB returns the work items using IN query expression. | [
"LoadBatchFromDB",
"returns",
"the",
"work",
"items",
"using",
"IN",
"query",
"expression",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L155-L166 |
13,428 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadByID | func (r *GormWorkItemRepository) LoadByID(ctx context.Context, id uuid.UUID) (*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadById"}, time.Now())
res, err := r.LoadFromDB(ctx, id)
if err != nil {
return nil, errs.WithStack(err)
}
wiType, err := r.witr.Load(ctx, res.Type)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return ConvertWorkItemStorageToModel(wiType, res)
} | go | func (r *GormWorkItemRepository) LoadByID(ctx context.Context, id uuid.UUID) (*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadById"}, time.Now())
res, err := r.LoadFromDB(ctx, id)
if err != nil {
return nil, errs.WithStack(err)
}
wiType, err := r.witr.Load(ctx, res.Type)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return ConvertWorkItemStorageToModel(wiType, res)
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadByID",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"*",
"WorkItem",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"res",
",",
"err",
":=",
"r",
".",
"LoadFromDB",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"wiType",
",",
"err",
":=",
"r",
".",
"witr",
".",
"Load",
"(",
"ctx",
",",
"res",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"res",
")",
"\n",
"}"
] | // LoadByID returns the work item for the given id
// returns NotFoundError, ConversionError or InternalError | [
"LoadByID",
"returns",
"the",
"work",
"item",
"for",
"the",
"given",
"id",
"returns",
"NotFoundError",
"ConversionError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L170-L181 |
13,429 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadBatchByID | func (r *GormWorkItemRepository) LoadBatchByID(ctx context.Context, ids []uuid.UUID) ([]*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadBatchById"}, time.Now())
res, err := r.LoadBatchFromDB(ctx, ids)
if err != nil {
return nil, errs.WithStack(err)
}
workitems := []*WorkItem{}
for _, ele := range res {
wiType, err := r.witr.Load(ctx, ele.Type)
if err != nil {
log.Error(nil, map[string]interface{}{
"wit_id": ele.Type,
"err": err,
}, "error in loading type from DB")
return nil, errors.NewInternalError(ctx, err)
}
convertedWI, err := ConvertWorkItemStorageToModel(wiType, &ele)
if err != nil {
log.Error(nil, map[string]interface{}{
"wi_id": ele.ID,
"err": err,
}, "error in converting WI")
}
workitems = append(workitems, convertedWI)
}
return workitems, nil
} | go | func (r *GormWorkItemRepository) LoadBatchByID(ctx context.Context, ids []uuid.UUID) ([]*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadBatchById"}, time.Now())
res, err := r.LoadBatchFromDB(ctx, ids)
if err != nil {
return nil, errs.WithStack(err)
}
workitems := []*WorkItem{}
for _, ele := range res {
wiType, err := r.witr.Load(ctx, ele.Type)
if err != nil {
log.Error(nil, map[string]interface{}{
"wit_id": ele.Type,
"err": err,
}, "error in loading type from DB")
return nil, errors.NewInternalError(ctx, err)
}
convertedWI, err := ConvertWorkItemStorageToModel(wiType, &ele)
if err != nil {
log.Error(nil, map[string]interface{}{
"wi_id": ele.ID,
"err": err,
}, "error in converting WI")
}
workitems = append(workitems, convertedWI)
}
return workitems, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadBatchByID",
"(",
"ctx",
"context",
".",
"Context",
",",
"ids",
"[",
"]",
"uuid",
".",
"UUID",
")",
"(",
"[",
"]",
"*",
"WorkItem",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"res",
",",
"err",
":=",
"r",
".",
"LoadBatchFromDB",
"(",
"ctx",
",",
"ids",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"workitems",
":=",
"[",
"]",
"*",
"WorkItem",
"{",
"}",
"\n",
"for",
"_",
",",
"ele",
":=",
"range",
"res",
"{",
"wiType",
",",
"err",
":=",
"r",
".",
"witr",
".",
"Load",
"(",
"ctx",
",",
"ele",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ele",
".",
"Type",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"convertedWI",
",",
"err",
":=",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"&",
"ele",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ele",
".",
"ID",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"workitems",
"=",
"append",
"(",
"workitems",
",",
"convertedWI",
")",
"\n",
"}",
"\n",
"return",
"workitems",
",",
"nil",
"\n",
"}"
] | // LoadBatchByID returns work items for the given ids | [
"LoadBatchByID",
"returns",
"work",
"items",
"for",
"the",
"given",
"ids"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L184-L210 |
13,430 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | Load | func (r *GormWorkItemRepository) Load(ctx context.Context, spaceID uuid.UUID, wiNumber int) (*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "load"}, time.Now())
wiStorage, wiType, err := r.loadWorkItemStorage(ctx, spaceID, wiNumber, false)
if err != nil {
return nil, err
}
return ConvertWorkItemStorageToModel(wiType, wiStorage)
} | go | func (r *GormWorkItemRepository) Load(ctx context.Context, spaceID uuid.UUID, wiNumber int) (*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "load"}, time.Now())
wiStorage, wiType, err := r.loadWorkItemStorage(ctx, spaceID, wiNumber, false)
if err != nil {
return nil, err
}
return ConvertWorkItemStorageToModel(wiType, wiStorage)
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"Load",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
",",
"wiNumber",
"int",
")",
"(",
"*",
"WorkItem",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"wiStorage",
",",
"wiType",
",",
"err",
":=",
"r",
".",
"loadWorkItemStorage",
"(",
"ctx",
",",
"spaceID",
",",
"wiNumber",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"wiStorage",
")",
"\n",
"}"
] | // Load returns the work item for the given spaceID and item id
// returns NotFoundError, ConversionError or InternalError | [
"Load",
"returns",
"the",
"work",
"item",
"for",
"the",
"given",
"spaceID",
"and",
"item",
"id",
"returns",
"NotFoundError",
"ConversionError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L214-L221 |
13,431 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LookupIDByNamedSpaceAndNumber | func (r *GormWorkItemRepository) LookupIDByNamedSpaceAndNumber(ctx context.Context, ownerName, spaceName string, wiNumber int) (*uuid.UUID, *uuid.UUID, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "lookupIDByNamedSpaceAndNumber"}, time.Now())
log.Debug(nil, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "Loading work item")
query := fmt.Sprintf(`select wi.id, wi.space_id from %[1]s wi
join %[2]s s on wi.space_id = s.id
join %[3]s i on s.owner_id = i.id
where lower(i.username) = lower(?) and
lower(s.name) = lower(?) and
wi.number = ? and
s.deleted_at IS NULL
and i.deleted_at IS NULL`,
WorkItemStorage{}.TableName(), space.Space{}.TableName(), account.Identity{}.TableName())
// 'scan' destination must be slice or struct
type Result struct {
WiID uuid.UUID `gorm:"column:id"`
// TODO(xcoulon) SpaceID can be removed once PR for #1452 is merged, as we won't need it anymore in the controller
SpaceID uuid.UUID
}
var result Result
db := r.db.Raw(query, ownerName, spaceName, wiNumber).Scan(&result)
if db.RecordNotFound() {
log.Error(nil, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "work item not found")
return nil, nil, errors.NewNotFoundError("work item", strconv.Itoa(wiNumber))
}
if db.Error != nil {
return nil, nil, errors.NewInternalError(ctx, errs.Wrap(db.Error, "error while looking up a work item ID"))
}
log.Debug(ctx, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "Matching work item with ID='%s' in space with ID='%s'", result.WiID.String(), result.SpaceID.String())
return &result.WiID, &result.SpaceID, nil
} | go | func (r *GormWorkItemRepository) LookupIDByNamedSpaceAndNumber(ctx context.Context, ownerName, spaceName string, wiNumber int) (*uuid.UUID, *uuid.UUID, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "lookupIDByNamedSpaceAndNumber"}, time.Now())
log.Debug(nil, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "Loading work item")
query := fmt.Sprintf(`select wi.id, wi.space_id from %[1]s wi
join %[2]s s on wi.space_id = s.id
join %[3]s i on s.owner_id = i.id
where lower(i.username) = lower(?) and
lower(s.name) = lower(?) and
wi.number = ? and
s.deleted_at IS NULL
and i.deleted_at IS NULL`,
WorkItemStorage{}.TableName(), space.Space{}.TableName(), account.Identity{}.TableName())
// 'scan' destination must be slice or struct
type Result struct {
WiID uuid.UUID `gorm:"column:id"`
// TODO(xcoulon) SpaceID can be removed once PR for #1452 is merged, as we won't need it anymore in the controller
SpaceID uuid.UUID
}
var result Result
db := r.db.Raw(query, ownerName, spaceName, wiNumber).Scan(&result)
if db.RecordNotFound() {
log.Error(nil, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "work item not found")
return nil, nil, errors.NewNotFoundError("work item", strconv.Itoa(wiNumber))
}
if db.Error != nil {
return nil, nil, errors.NewInternalError(ctx, errs.Wrap(db.Error, "error while looking up a work item ID"))
}
log.Debug(ctx, map[string]interface{}{
"wi_number": wiNumber,
"space_name": spaceName,
"owner_name": ownerName,
}, "Matching work item with ID='%s' in space with ID='%s'", result.WiID.String(), result.SpaceID.String())
return &result.WiID, &result.SpaceID, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LookupIDByNamedSpaceAndNumber",
"(",
"ctx",
"context",
".",
"Context",
",",
"ownerName",
",",
"spaceName",
"string",
",",
"wiNumber",
"int",
")",
"(",
"*",
"uuid",
".",
"UUID",
",",
"*",
"uuid",
".",
"UUID",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"log",
".",
"Debug",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"wiNumber",
",",
"\"",
"\"",
":",
"spaceName",
",",
"\"",
"\"",
":",
"ownerName",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"query",
":=",
"fmt",
".",
"Sprintf",
"(",
"`select wi.id, wi.space_id from %[1]s wi\n\t\tjoin %[2]s s on wi.space_id = s.id\n\t\tjoin %[3]s i on s.owner_id = i.id\n\t\twhere lower(i.username) = lower(?) and\n\t\tlower(s.name) = lower(?) and\n\t\twi.number = ? and\n\t\ts.deleted_at IS NULL\n\t\tand i.deleted_at IS NULL`",
",",
"WorkItemStorage",
"{",
"}",
".",
"TableName",
"(",
")",
",",
"space",
".",
"Space",
"{",
"}",
".",
"TableName",
"(",
")",
",",
"account",
".",
"Identity",
"{",
"}",
".",
"TableName",
"(",
")",
")",
"\n",
"// 'scan' destination must be slice or struct",
"type",
"Result",
"struct",
"{",
"WiID",
"uuid",
".",
"UUID",
"`gorm:\"column:id\"`",
"\n",
"// TODO(xcoulon) SpaceID can be removed once PR for #1452 is merged, as we won't need it anymore in the controller",
"SpaceID",
"uuid",
".",
"UUID",
"\n",
"}",
"\n",
"var",
"result",
"Result",
"\n",
"db",
":=",
"r",
".",
"db",
".",
"Raw",
"(",
"query",
",",
"ownerName",
",",
"spaceName",
",",
"wiNumber",
")",
".",
"Scan",
"(",
"&",
"result",
")",
"\n",
"if",
"db",
".",
"RecordNotFound",
"(",
")",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"wiNumber",
",",
"\"",
"\"",
":",
"spaceName",
",",
"\"",
"\"",
":",
"ownerName",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"wiNumber",
")",
")",
"\n",
"}",
"\n",
"if",
"db",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"errs",
".",
"Wrap",
"(",
"db",
".",
"Error",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"wiNumber",
",",
"\"",
"\"",
":",
"spaceName",
",",
"\"",
"\"",
":",
"ownerName",
",",
"}",
",",
"\"",
"\"",
",",
"result",
".",
"WiID",
".",
"String",
"(",
")",
",",
"result",
".",
"SpaceID",
".",
"String",
"(",
")",
")",
"\n",
"return",
"&",
"result",
".",
"WiID",
",",
"&",
"result",
".",
"SpaceID",
",",
"nil",
"\n",
"}"
] | // LookupIDByNamedSpaceAndNumber returns the work item's ID for the given owner name, space name and item number
// returns NotFoundError, ConversionError or InternalError | [
"LookupIDByNamedSpaceAndNumber",
"returns",
"the",
"work",
"item",
"s",
"ID",
"for",
"the",
"given",
"owner",
"name",
"space",
"name",
"and",
"item",
"number",
"returns",
"NotFoundError",
"ConversionError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L225-L266 |
13,432 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadBottomWorkitem | func (r *GormWorkItemRepository) LoadBottomWorkitem(ctx context.Context, spaceID uuid.UUID) (*WorkItem, error) {
res := WorkItemStorage{}
db := r.db.Model(WorkItemStorage{})
query := fmt.Sprintf("execution_order = (SELECT min(execution_order) FROM %[1]s where space_id=?)",
WorkItemStorage{}.TableName(),
)
db = db.Where(query, spaceID).First(&res)
if db.Error != nil && !db.RecordNotFound() {
return nil, errors.NewInternalError(ctx, db.Error)
}
wiType, err := r.witr.Load(ctx, res.Type)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return ConvertWorkItemStorageToModel(wiType, &res)
} | go | func (r *GormWorkItemRepository) LoadBottomWorkitem(ctx context.Context, spaceID uuid.UUID) (*WorkItem, error) {
res := WorkItemStorage{}
db := r.db.Model(WorkItemStorage{})
query := fmt.Sprintf("execution_order = (SELECT min(execution_order) FROM %[1]s where space_id=?)",
WorkItemStorage{}.TableName(),
)
db = db.Where(query, spaceID).First(&res)
if db.Error != nil && !db.RecordNotFound() {
return nil, errors.NewInternalError(ctx, db.Error)
}
wiType, err := r.witr.Load(ctx, res.Type)
if err != nil {
return nil, errors.NewInternalError(ctx, err)
}
return ConvertWorkItemStorageToModel(wiType, &res)
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadBottomWorkitem",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
")",
"(",
"*",
"WorkItem",
",",
"error",
")",
"{",
"res",
":=",
"WorkItemStorage",
"{",
"}",
"\n",
"db",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"WorkItemStorage",
"{",
"}",
")",
"\n",
"query",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"WorkItemStorage",
"{",
"}",
".",
"TableName",
"(",
")",
",",
")",
"\n",
"db",
"=",
"db",
".",
"Where",
"(",
"query",
",",
"spaceID",
")",
".",
"First",
"(",
"&",
"res",
")",
"\n",
"if",
"db",
".",
"Error",
"!=",
"nil",
"&&",
"!",
"db",
".",
"RecordNotFound",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"db",
".",
"Error",
")",
"\n",
"}",
"\n",
"wiType",
",",
"err",
":=",
"r",
".",
"witr",
".",
"Load",
"(",
"ctx",
",",
"res",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"&",
"res",
")",
"\n",
"}"
] | // LoadBottomWorkitem returns bottom work item of the list. Bottom most workitem has the lowest order.
// returns NotFoundError, ConversionError or InternalError | [
"LoadBottomWorkitem",
"returns",
"bottom",
"work",
"item",
"of",
"the",
"list",
".",
"Bottom",
"most",
"workitem",
"has",
"the",
"lowest",
"order",
".",
"returns",
"NotFoundError",
"ConversionError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L324-L339 |
13,433 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadHighestOrder | func (r *GormWorkItemRepository) LoadHighestOrder(ctx context.Context, spaceID uuid.UUID) (float64, error) {
res := WorkItemStorage{}
db := r.db.Model(WorkItemStorage{})
query := fmt.Sprintf("execution_order = (SELECT max(execution_order) FROM %[1]s where space_id=?)",
WorkItemStorage{}.TableName(),
)
db = db.Where(query, spaceID).First(&res)
if db.Error != nil && !db.RecordNotFound() {
return 0, errors.NewInternalError(ctx, db.Error)
}
order, err := strconv.ParseFloat(fmt.Sprintf("%v", res.ExecutionOrder), 64)
if err != nil {
return 0, errors.NewInternalError(ctx, err)
}
return order, nil
} | go | func (r *GormWorkItemRepository) LoadHighestOrder(ctx context.Context, spaceID uuid.UUID) (float64, error) {
res := WorkItemStorage{}
db := r.db.Model(WorkItemStorage{})
query := fmt.Sprintf("execution_order = (SELECT max(execution_order) FROM %[1]s where space_id=?)",
WorkItemStorage{}.TableName(),
)
db = db.Where(query, spaceID).First(&res)
if db.Error != nil && !db.RecordNotFound() {
return 0, errors.NewInternalError(ctx, db.Error)
}
order, err := strconv.ParseFloat(fmt.Sprintf("%v", res.ExecutionOrder), 64)
if err != nil {
return 0, errors.NewInternalError(ctx, err)
}
return order, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadHighestOrder",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
")",
"(",
"float64",
",",
"error",
")",
"{",
"res",
":=",
"WorkItemStorage",
"{",
"}",
"\n",
"db",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"WorkItemStorage",
"{",
"}",
")",
"\n",
"query",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"WorkItemStorage",
"{",
"}",
".",
"TableName",
"(",
")",
",",
")",
"\n",
"db",
"=",
"db",
".",
"Where",
"(",
"query",
",",
"spaceID",
")",
".",
"First",
"(",
"&",
"res",
")",
"\n",
"if",
"db",
".",
"Error",
"!=",
"nil",
"&&",
"!",
"db",
".",
"RecordNotFound",
"(",
")",
"{",
"return",
"0",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"db",
".",
"Error",
")",
"\n",
"}",
"\n",
"order",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"res",
".",
"ExecutionOrder",
")",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"order",
",",
"nil",
"\n",
"}"
] | // LoadHighestOrder returns the highest execution order in the given space | [
"LoadHighestOrder",
"returns",
"the",
"highest",
"execution",
"order",
"in",
"the",
"given",
"space"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L342-L357 |
13,434 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | Delete | func (r *GormWorkItemRepository) Delete(ctx context.Context, workitemID uuid.UUID, suppressorID uuid.UUID) error {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "delete"}, time.Now())
var workItem = WorkItemStorage{}
workItem.ID = workitemID
// retrieve the current version of the work item to delete
r.db.Select("id, version, type").Where("id = ?", workitemID).Find(&workItem)
// delete the work item
tx := r.db.Delete(workItem)
if err := tx.Error; err != nil {
return errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
return errors.NewNotFoundError("work item", workitemID.String())
}
// store a revision of the deleted work item
_, err := r.wirr.Create(context.Background(), suppressorID, RevisionTypeDelete, workItem)
if err != nil {
return errs.Wrapf(err, "error while deleting work item")
}
log.Debug(ctx, map[string]interface{}{"wi_id": workitemID}, "Work item deleted successfully!")
return nil
} | go | func (r *GormWorkItemRepository) Delete(ctx context.Context, workitemID uuid.UUID, suppressorID uuid.UUID) error {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "delete"}, time.Now())
var workItem = WorkItemStorage{}
workItem.ID = workitemID
// retrieve the current version of the work item to delete
r.db.Select("id, version, type").Where("id = ?", workitemID).Find(&workItem)
// delete the work item
tx := r.db.Delete(workItem)
if err := tx.Error; err != nil {
return errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
return errors.NewNotFoundError("work item", workitemID.String())
}
// store a revision of the deleted work item
_, err := r.wirr.Create(context.Background(), suppressorID, RevisionTypeDelete, workItem)
if err != nil {
return errs.Wrapf(err, "error while deleting work item")
}
log.Debug(ctx, map[string]interface{}{"wi_id": workitemID}, "Work item deleted successfully!")
return nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"workitemID",
"uuid",
".",
"UUID",
",",
"suppressorID",
"uuid",
".",
"UUID",
")",
"error",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"var",
"workItem",
"=",
"WorkItemStorage",
"{",
"}",
"\n",
"workItem",
".",
"ID",
"=",
"workitemID",
"\n",
"// retrieve the current version of the work item to delete",
"r",
".",
"db",
".",
"Select",
"(",
"\"",
"\"",
")",
".",
"Where",
"(",
"\"",
"\"",
",",
"workitemID",
")",
".",
"Find",
"(",
"&",
"workItem",
")",
"\n",
"// delete the work item",
"tx",
":=",
"r",
".",
"db",
".",
"Delete",
"(",
"workItem",
")",
"\n",
"if",
"err",
":=",
"tx",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"tx",
".",
"RowsAffected",
"==",
"0",
"{",
"return",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"workitemID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"// store a revision of the deleted work item",
"_",
",",
"err",
":=",
"r",
".",
"wirr",
".",
"Create",
"(",
"context",
".",
"Background",
"(",
")",
",",
"suppressorID",
",",
"RevisionTypeDelete",
",",
"workItem",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workitemID",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete deletes the work item with the given id
// returns NotFoundError or InternalError | [
"Delete",
"deletes",
"the",
"work",
"item",
"with",
"the",
"given",
"id",
"returns",
"NotFoundError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L361-L382 |
13,435 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | FindFirstItem | func (r *GormWorkItemRepository) FindFirstItem(ctx context.Context, spaceID uuid.UUID, id uuid.UUID) (*float64, error) {
res := WorkItemStorage{}
tx := r.db.Model(WorkItemStorage{}).Where("id=? and space_id=?", id, spaceID).First(&res)
if tx.RecordNotFound() {
return nil, errors.NewNotFoundError("work item", id.String())
}
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
return &res.ExecutionOrder, nil
} | go | func (r *GormWorkItemRepository) FindFirstItem(ctx context.Context, spaceID uuid.UUID, id uuid.UUID) (*float64, error) {
res := WorkItemStorage{}
tx := r.db.Model(WorkItemStorage{}).Where("id=? and space_id=?", id, spaceID).First(&res)
if tx.RecordNotFound() {
return nil, errors.NewNotFoundError("work item", id.String())
}
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
return &res.ExecutionOrder, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"FindFirstItem",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
",",
"id",
"uuid",
".",
"UUID",
")",
"(",
"*",
"float64",
",",
"error",
")",
"{",
"res",
":=",
"WorkItemStorage",
"{",
"}",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"WorkItemStorage",
"{",
"}",
")",
".",
"Where",
"(",
"\"",
"\"",
",",
"id",
",",
"spaceID",
")",
".",
"First",
"(",
"&",
"res",
")",
"\n",
"if",
"tx",
".",
"RecordNotFound",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"id",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"tx",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"tx",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"&",
"res",
".",
"ExecutionOrder",
",",
"nil",
"\n",
"}"
] | // FindFirstItem returns the order of the target workitem | [
"FindFirstItem",
"returns",
"the",
"order",
"of",
"the",
"target",
"workitem"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L425-L435 |
13,436 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | ConvertWorkItemStorageToModel | func ConvertWorkItemStorageToModel(wiType *WorkItemType, wi *WorkItemStorage) (*WorkItem, error) {
result, err := wiType.ConvertWorkItemStorageToModel(*wi)
if err != nil {
return nil, errors.NewConversionError(err.Error())
}
if _, ok := wiType.Fields[SystemCreatedAt]; ok {
result.Fields[SystemCreatedAt] = wi.CreatedAt
}
if _, ok := wiType.Fields[SystemUpdatedAt]; ok {
result.Fields[SystemUpdatedAt] = wi.UpdatedAt
}
if _, ok := wiType.Fields[SystemOrder]; ok {
result.Fields[SystemOrder] = wi.ExecutionOrder
}
if _, ok := wiType.Fields[SystemNumber]; ok {
result.Fields[SystemNumber] = wi.Number
}
return result, nil
} | go | func ConvertWorkItemStorageToModel(wiType *WorkItemType, wi *WorkItemStorage) (*WorkItem, error) {
result, err := wiType.ConvertWorkItemStorageToModel(*wi)
if err != nil {
return nil, errors.NewConversionError(err.Error())
}
if _, ok := wiType.Fields[SystemCreatedAt]; ok {
result.Fields[SystemCreatedAt] = wi.CreatedAt
}
if _, ok := wiType.Fields[SystemUpdatedAt]; ok {
result.Fields[SystemUpdatedAt] = wi.UpdatedAt
}
if _, ok := wiType.Fields[SystemOrder]; ok {
result.Fields[SystemOrder] = wi.ExecutionOrder
}
if _, ok := wiType.Fields[SystemNumber]; ok {
result.Fields[SystemNumber] = wi.Number
}
return result, nil
} | [
"func",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
"*",
"WorkItemType",
",",
"wi",
"*",
"WorkItemStorage",
")",
"(",
"*",
"WorkItem",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"wiType",
".",
"ConvertWorkItemStorageToModel",
"(",
"*",
"wi",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewConversionError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"wiType",
".",
"Fields",
"[",
"SystemCreatedAt",
"]",
";",
"ok",
"{",
"result",
".",
"Fields",
"[",
"SystemCreatedAt",
"]",
"=",
"wi",
".",
"CreatedAt",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"wiType",
".",
"Fields",
"[",
"SystemUpdatedAt",
"]",
";",
"ok",
"{",
"result",
".",
"Fields",
"[",
"SystemUpdatedAt",
"]",
"=",
"wi",
".",
"UpdatedAt",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"wiType",
".",
"Fields",
"[",
"SystemOrder",
"]",
";",
"ok",
"{",
"result",
".",
"Fields",
"[",
"SystemOrder",
"]",
"=",
"wi",
".",
"ExecutionOrder",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"wiType",
".",
"Fields",
"[",
"SystemNumber",
"]",
";",
"ok",
"{",
"result",
".",
"Fields",
"[",
"SystemNumber",
"]",
"=",
"wi",
".",
"Number",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n\n",
"}"
] | // ConvertWorkItemStorageToModel convert work item model to app WI | [
"ConvertWorkItemStorageToModel",
"convert",
"work",
"item",
"model",
"to",
"app",
"WI"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L766-L785 |
13,437 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | Count | func (r *GormWorkItemRepository) Count(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (int, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "count"}, time.Now())
where, parameters, joins, compileError := Compile(criteria)
if compileError != nil {
return 0, errors.NewBadParameterError("expression", criteria)
}
where = where + " AND space_id = ?"
parameters = append(parameters, spaceID)
var count int
db := r.db.Model(&WorkItemStorage{}).Where(where, parameters...)
for _, j := range joins {
if err := j.Validate(db); err != nil {
log.Error(ctx, map[string]interface{}{"expression": criteria, "err": err}, "table join not valid")
return 0, errors.NewBadParameterError("expression", criteria).Expected("valid table join")
}
db = db.Joins(j.GetJoinExpression())
}
db = db.Count(&count)
if db.Error != nil {
return 0, errors.NewInternalError(ctx, errs.Wrapf(db.Error, "failed to count work items that match this criteria: %s", criteria))
}
return count, nil
} | go | func (r *GormWorkItemRepository) Count(ctx context.Context, spaceID uuid.UUID, criteria criteria.Expression) (int, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "count"}, time.Now())
where, parameters, joins, compileError := Compile(criteria)
if compileError != nil {
return 0, errors.NewBadParameterError("expression", criteria)
}
where = where + " AND space_id = ?"
parameters = append(parameters, spaceID)
var count int
db := r.db.Model(&WorkItemStorage{}).Where(where, parameters...)
for _, j := range joins {
if err := j.Validate(db); err != nil {
log.Error(ctx, map[string]interface{}{"expression": criteria, "err": err}, "table join not valid")
return 0, errors.NewBadParameterError("expression", criteria).Expected("valid table join")
}
db = db.Joins(j.GetJoinExpression())
}
db = db.Count(&count)
if db.Error != nil {
return 0, errors.NewInternalError(ctx, errs.Wrapf(db.Error, "failed to count work items that match this criteria: %s", criteria))
}
return count, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"Count",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
",",
"criteria",
"criteria",
".",
"Expression",
")",
"(",
"int",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n\n",
"where",
",",
"parameters",
",",
"joins",
",",
"compileError",
":=",
"Compile",
"(",
"criteria",
")",
"\n",
"if",
"compileError",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"criteria",
")",
"\n",
"}",
"\n",
"where",
"=",
"where",
"+",
"\"",
"\"",
"\n",
"parameters",
"=",
"append",
"(",
"parameters",
",",
"spaceID",
")",
"\n\n",
"var",
"count",
"int",
"\n",
"db",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"&",
"WorkItemStorage",
"{",
"}",
")",
".",
"Where",
"(",
"where",
",",
"parameters",
"...",
")",
"\n",
"for",
"_",
",",
"j",
":=",
"range",
"joins",
"{",
"if",
"err",
":=",
"j",
".",
"Validate",
"(",
"db",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"criteria",
",",
"\"",
"\"",
":",
"err",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"0",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"criteria",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"db",
"=",
"db",
".",
"Joins",
"(",
"j",
".",
"GetJoinExpression",
"(",
")",
")",
"\n",
"}",
"\n",
"db",
"=",
"db",
".",
"Count",
"(",
"&",
"count",
")",
"\n",
"if",
"db",
".",
"Error",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"errs",
".",
"Wrapf",
"(",
"db",
".",
"Error",
",",
"\"",
"\"",
",",
"criteria",
")",
")",
"\n",
"}",
"\n",
"return",
"count",
",",
"nil",
"\n",
"}"
] | // Count returns the amount of work item that satisfy the given criteria.Expression | [
"Count",
"returns",
"the",
"amount",
"of",
"work",
"item",
"that",
"satisfy",
"the",
"given",
"criteria",
".",
"Expression"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L908-L932 |
13,438 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | GetCountsPerIteration | func (r *GormWorkItemRepository) GetCountsPerIteration(ctx context.Context, spaceID uuid.UUID) (map[string]WICountsPerIteration, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "getCountsPerIteration"}, time.Now())
db := r.db.Model(&iteration.Iteration{}).Where("space_id = ?", spaceID)
if db.Error != nil {
return nil, errors.NewInternalError(ctx, db.Error)
}
wiMap, err := r.getAllIterationWithCounts(ctx, db, spaceID)
if err != nil {
return nil, err
}
countsMap, err := r.getFinalCountAddingChild(ctx, db, spaceID, wiMap)
if err != nil {
return nil, err
}
return countsMap, nil
} | go | func (r *GormWorkItemRepository) GetCountsPerIteration(ctx context.Context, spaceID uuid.UUID) (map[string]WICountsPerIteration, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "getCountsPerIteration"}, time.Now())
db := r.db.Model(&iteration.Iteration{}).Where("space_id = ?", spaceID)
if db.Error != nil {
return nil, errors.NewInternalError(ctx, db.Error)
}
wiMap, err := r.getAllIterationWithCounts(ctx, db, spaceID)
if err != nil {
return nil, err
}
countsMap, err := r.getFinalCountAddingChild(ctx, db, spaceID, wiMap)
if err != nil {
return nil, err
}
return countsMap, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"GetCountsPerIteration",
"(",
"ctx",
"context",
".",
"Context",
",",
"spaceID",
"uuid",
".",
"UUID",
")",
"(",
"map",
"[",
"string",
"]",
"WICountsPerIteration",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"db",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"&",
"iteration",
".",
"Iteration",
"{",
"}",
")",
".",
"Where",
"(",
"\"",
"\"",
",",
"spaceID",
")",
"\n",
"if",
"db",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"db",
".",
"Error",
")",
"\n",
"}",
"\n\n",
"wiMap",
",",
"err",
":=",
"r",
".",
"getAllIterationWithCounts",
"(",
"ctx",
",",
"db",
",",
"spaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"countsMap",
",",
"err",
":=",
"r",
".",
"getFinalCountAddingChild",
"(",
"ctx",
",",
"db",
",",
"spaceID",
",",
"wiMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"countsMap",
",",
"nil",
"\n",
"}"
] | // GetCountsPerIteration counts WIs including iteration-children and returns a map of iterationID->WICountsPerIteration | [
"GetCountsPerIteration",
"counts",
"WIs",
"including",
"iteration",
"-",
"children",
"and",
"returns",
"a",
"map",
"of",
"iterationID",
"-",
">",
"WICountsPerIteration"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L1062-L1079 |
13,439 | fabric8-services/fabric8-wit | workitem/workitem_repository.go | LoadByIteration | func (r *GormWorkItemRepository) LoadByIteration(ctx context.Context, iterationID uuid.UUID) ([]*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadByIteration"}, time.Now())
log.Info(nil, map[string]interface{}{
"itr_id": iterationID,
}, "Loading work items for iteration")
res := []WorkItemStorage{}
filter := fmt.Sprintf(`fields @> '{"%s":"%s"}'`, SystemIteration, iterationID)
tx := r.db.Model(WorkItemStorage{}).Where(filter).Find(&res)
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
workitems := []*WorkItem{}
for _, ele := range res {
wiType, err := r.witr.Load(ctx, ele.Type)
if err != nil {
log.Error(nil, map[string]interface{}{
"wit_id": ele.Type,
"err": err,
}, "error in loading type from DB")
return nil, errors.NewInternalError(ctx, err)
}
convertedWI, err := ConvertWorkItemStorageToModel(wiType, &ele)
if err != nil {
log.Error(nil, map[string]interface{}{
"wi_id": ele.ID,
"err": err,
}, "error in converting WI")
return nil, errs.Wrap(err, "error when converting WI")
}
workitems = append(workitems, convertedWI)
}
return workitems, nil
} | go | func (r *GormWorkItemRepository) LoadByIteration(ctx context.Context, iterationID uuid.UUID) ([]*WorkItem, error) {
defer goa.MeasureSince([]string{"goa", "db", "workitem", "loadByIteration"}, time.Now())
log.Info(nil, map[string]interface{}{
"itr_id": iterationID,
}, "Loading work items for iteration")
res := []WorkItemStorage{}
filter := fmt.Sprintf(`fields @> '{"%s":"%s"}'`, SystemIteration, iterationID)
tx := r.db.Model(WorkItemStorage{}).Where(filter).Find(&res)
if tx.Error != nil {
return nil, errors.NewInternalError(ctx, tx.Error)
}
workitems := []*WorkItem{}
for _, ele := range res {
wiType, err := r.witr.Load(ctx, ele.Type)
if err != nil {
log.Error(nil, map[string]interface{}{
"wit_id": ele.Type,
"err": err,
}, "error in loading type from DB")
return nil, errors.NewInternalError(ctx, err)
}
convertedWI, err := ConvertWorkItemStorageToModel(wiType, &ele)
if err != nil {
log.Error(nil, map[string]interface{}{
"wi_id": ele.ID,
"err": err,
}, "error in converting WI")
return nil, errs.Wrap(err, "error when converting WI")
}
workitems = append(workitems, convertedWI)
}
return workitems, nil
} | [
"func",
"(",
"r",
"*",
"GormWorkItemRepository",
")",
"LoadByIteration",
"(",
"ctx",
"context",
".",
"Context",
",",
"iterationID",
"uuid",
".",
"UUID",
")",
"(",
"[",
"]",
"*",
"WorkItem",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"iterationID",
",",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"res",
":=",
"[",
"]",
"WorkItemStorage",
"{",
"}",
"\n",
"filter",
":=",
"fmt",
".",
"Sprintf",
"(",
"`fields @> '{\"%s\":\"%s\"}'`",
",",
"SystemIteration",
",",
"iterationID",
")",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Model",
"(",
"WorkItemStorage",
"{",
"}",
")",
".",
"Where",
"(",
"filter",
")",
".",
"Find",
"(",
"&",
"res",
")",
"\n",
"if",
"tx",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"tx",
".",
"Error",
")",
"\n",
"}",
"\n",
"workitems",
":=",
"[",
"]",
"*",
"WorkItem",
"{",
"}",
"\n",
"for",
"_",
",",
"ele",
":=",
"range",
"res",
"{",
"wiType",
",",
"err",
":=",
"r",
".",
"witr",
".",
"Load",
"(",
"ctx",
",",
"ele",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ele",
".",
"Type",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"convertedWI",
",",
"err",
":=",
"ConvertWorkItemStorageToModel",
"(",
"wiType",
",",
"&",
"ele",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ele",
".",
"ID",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"workitems",
"=",
"append",
"(",
"workitems",
",",
"convertedWI",
")",
"\n",
"}",
"\n",
"return",
"workitems",
",",
"nil",
"\n",
"}"
] | // LoadByIteration returns the list of work items belongs to given iteration | [
"LoadByIteration",
"returns",
"the",
"list",
"of",
"work",
"items",
"belongs",
"to",
"given",
"iteration"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_repository.go#L1145-L1178 |
13,440 | fabric8-services/fabric8-wit | controller/namedspaces.go | NewNamedspacesController | func NewNamedspacesController(service *goa.Service, db application.DB) *NamedspacesController {
return &NamedspacesController{Controller: service.NewController("NamedspacesController"), db: db}
} | go | func NewNamedspacesController(service *goa.Service, db application.DB) *NamedspacesController {
return &NamedspacesController{Controller: service.NewController("NamedspacesController"), db: db}
} | [
"func",
"NewNamedspacesController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
")",
"*",
"NamedspacesController",
"{",
"return",
"&",
"NamedspacesController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
"}",
"\n",
"}"
] | // NewNamedspacesController creates a namedspaces controller. | [
"NewNamedspacesController",
"creates",
"a",
"namedspaces",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/namedspaces.go#L23-L25 |
13,441 | fabric8-services/fabric8-wit | workitem/workitem_storage.go | Equal | func (wi WorkItemStorage) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemStorage)
if !ok {
return false
}
if !convert.CascadeEqual(wi.Lifecycle, other.Lifecycle) {
return false
}
if wi.Number != other.Number {
return false
}
if wi.Type != other.Type {
return false
}
if wi.ID != other.ID {
return false
}
if wi.Version != other.Version {
return false
}
if wi.ExecutionOrder != other.ExecutionOrder {
return false
}
if wi.Number != other.Number {
return false
}
if wi.SpaceID != other.SpaceID {
return false
}
if !reflect.DeepEqual(wi.RelationShipsChangedAt, other.RelationShipsChangedAt) {
return false
}
return convert.CascadeEqual(wi.Fields, other.Fields)
} | go | func (wi WorkItemStorage) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemStorage)
if !ok {
return false
}
if !convert.CascadeEqual(wi.Lifecycle, other.Lifecycle) {
return false
}
if wi.Number != other.Number {
return false
}
if wi.Type != other.Type {
return false
}
if wi.ID != other.ID {
return false
}
if wi.Version != other.Version {
return false
}
if wi.ExecutionOrder != other.ExecutionOrder {
return false
}
if wi.Number != other.Number {
return false
}
if wi.SpaceID != other.SpaceID {
return false
}
if !reflect.DeepEqual(wi.RelationShipsChangedAt, other.RelationShipsChangedAt) {
return false
}
return convert.CascadeEqual(wi.Fields, other.Fields)
} | [
"func",
"(",
"wi",
"WorkItemStorage",
")",
"Equal",
"(",
"u",
"convert",
".",
"Equaler",
")",
"bool",
"{",
"other",
",",
"ok",
":=",
"u",
".",
"(",
"WorkItemStorage",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"convert",
".",
"CascadeEqual",
"(",
"wi",
".",
"Lifecycle",
",",
"other",
".",
"Lifecycle",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"Number",
"!=",
"other",
".",
"Number",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"Type",
"!=",
"other",
".",
"Type",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"ID",
"!=",
"other",
".",
"ID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"Version",
"!=",
"other",
".",
"Version",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"ExecutionOrder",
"!=",
"other",
".",
"ExecutionOrder",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"Number",
"!=",
"other",
".",
"Number",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wi",
".",
"SpaceID",
"!=",
"other",
".",
"SpaceID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"wi",
".",
"RelationShipsChangedAt",
",",
"other",
".",
"RelationShipsChangedAt",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"convert",
".",
"CascadeEqual",
"(",
"wi",
".",
"Fields",
",",
"other",
".",
"Fields",
")",
"\n",
"}"
] | // Equal returns true if two WorkItem objects are equal; otherwise false is returned. | [
"Equal",
"returns",
"true",
"if",
"two",
"WorkItem",
"objects",
"are",
"equal",
";",
"otherwise",
"false",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_storage.go#L50-L83 |
13,442 | fabric8-services/fabric8-wit | workitem/workitem_storage.go | ParseWorkItemIDToUint64 | func ParseWorkItemIDToUint64(wiIDStr string) (uint64, error) {
wiID, err := strconv.ParseUint(wiIDStr, 10, 64)
if err != nil {
return 0, errors.NewNotFoundError("work item ID", wiIDStr)
}
return wiID, nil
} | go | func ParseWorkItemIDToUint64(wiIDStr string) (uint64, error) {
wiID, err := strconv.ParseUint(wiIDStr, 10, 64)
if err != nil {
return 0, errors.NewNotFoundError("work item ID", wiIDStr)
}
return wiID, nil
} | [
"func",
"ParseWorkItemIDToUint64",
"(",
"wiIDStr",
"string",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"wiID",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"wiIDStr",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"wiIDStr",
")",
"\n",
"}",
"\n",
"return",
"wiID",
",",
"nil",
"\n",
"}"
] | // ParseWorkItemIDToUint64 does what it says | [
"ParseWorkItemIDToUint64",
"does",
"what",
"it",
"says"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitem_storage.go#L98-L104 |
13,443 | fabric8-services/fabric8-wit | migration/migration.go | MigrateToNextVersion | func MigrateToNextVersion(tx *sql.Tx, nextVersion *int64, m Migrations, catalog string) error {
// Obtain exclusive transaction level advisory that doesn't depend on any table.
// Once obtained, the lock is held for the remainder of the current transaction.
// (There is no UNLOCK TABLE command; locks are always released at transaction end.)
if _, err := tx.Exec("SELECT pg_advisory_xact_lock($1)", AdvisoryLockID); err != nil {
return errs.Wrapf(err, "failed to acquire lock: %s\n", AdvisoryLockID)
}
// Determine current version and adjust the outmost loop
// iterator variable "version"
currentVersion, err := getCurrentVersion(tx, catalog)
if err != nil {
return errs.WithStack(err)
}
*nextVersion = currentVersion + 1
if *nextVersion >= int64(len(m)) {
// No further updates to apply (this is NOT an error)
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Current version %d. Nothing to update.", currentVersion)
return nil
}
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Attempt to update DB to version %v", *nextVersion)
// Apply all the updates of the next version
for j := range m[*nextVersion] {
if err := m[*nextVersion][j](tx); err != nil {
return errs.Errorf("failed to execute migration of step %d of version %d: %s\n", j, *nextVersion, err)
}
}
if _, err := tx.Exec("INSERT INTO version(version) VALUES($1)", *nextVersion); err != nil {
return errs.Errorf("failed to update DB to version %d: %s\n", *nextVersion, err)
}
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Successfully updated DB to version %v", *nextVersion)
return nil
} | go | func MigrateToNextVersion(tx *sql.Tx, nextVersion *int64, m Migrations, catalog string) error {
// Obtain exclusive transaction level advisory that doesn't depend on any table.
// Once obtained, the lock is held for the remainder of the current transaction.
// (There is no UNLOCK TABLE command; locks are always released at transaction end.)
if _, err := tx.Exec("SELECT pg_advisory_xact_lock($1)", AdvisoryLockID); err != nil {
return errs.Wrapf(err, "failed to acquire lock: %s\n", AdvisoryLockID)
}
// Determine current version and adjust the outmost loop
// iterator variable "version"
currentVersion, err := getCurrentVersion(tx, catalog)
if err != nil {
return errs.WithStack(err)
}
*nextVersion = currentVersion + 1
if *nextVersion >= int64(len(m)) {
// No further updates to apply (this is NOT an error)
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Current version %d. Nothing to update.", currentVersion)
return nil
}
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Attempt to update DB to version %v", *nextVersion)
// Apply all the updates of the next version
for j := range m[*nextVersion] {
if err := m[*nextVersion][j](tx); err != nil {
return errs.Errorf("failed to execute migration of step %d of version %d: %s\n", j, *nextVersion, err)
}
}
if _, err := tx.Exec("INSERT INTO version(version) VALUES($1)", *nextVersion); err != nil {
return errs.Errorf("failed to update DB to version %d: %s\n", *nextVersion, err)
}
log.Info(nil, map[string]interface{}{
"next_version": *nextVersion,
"current_version": currentVersion,
}, "Successfully updated DB to version %v", *nextVersion)
return nil
} | [
"func",
"MigrateToNextVersion",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"nextVersion",
"*",
"int64",
",",
"m",
"Migrations",
",",
"catalog",
"string",
")",
"error",
"{",
"// Obtain exclusive transaction level advisory that doesn't depend on any table.",
"// Once obtained, the lock is held for the remainder of the current transaction.",
"// (There is no UNLOCK TABLE command; locks are always released at transaction end.)",
"if",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"\"",
"\"",
",",
"AdvisoryLockID",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\\n",
"\"",
",",
"AdvisoryLockID",
")",
"\n",
"}",
"\n\n",
"// Determine current version and adjust the outmost loop",
"// iterator variable \"version\"",
"currentVersion",
",",
"err",
":=",
"getCurrentVersion",
"(",
"tx",
",",
"catalog",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"*",
"nextVersion",
"=",
"currentVersion",
"+",
"1",
"\n",
"if",
"*",
"nextVersion",
">=",
"int64",
"(",
"len",
"(",
"m",
")",
")",
"{",
"// No further updates to apply (this is NOT an error)",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"*",
"nextVersion",
",",
"\"",
"\"",
":",
"currentVersion",
",",
"}",
",",
"\"",
"\"",
",",
"currentVersion",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"*",
"nextVersion",
",",
"\"",
"\"",
":",
"currentVersion",
",",
"}",
",",
"\"",
"\"",
",",
"*",
"nextVersion",
")",
"\n\n",
"// Apply all the updates of the next version",
"for",
"j",
":=",
"range",
"m",
"[",
"*",
"nextVersion",
"]",
"{",
"if",
"err",
":=",
"m",
"[",
"*",
"nextVersion",
"]",
"[",
"j",
"]",
"(",
"tx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"j",
",",
"*",
"nextVersion",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"\"",
"\"",
",",
"*",
"nextVersion",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"*",
"nextVersion",
",",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"*",
"nextVersion",
",",
"\"",
"\"",
":",
"currentVersion",
",",
"}",
",",
"\"",
"\"",
",",
"*",
"nextVersion",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // MigrateToNextVersion migrates the database to the nextVersion.
// If the database is already at nextVersion or higher, the nextVersion
// will be set to the actual next version. | [
"MigrateToNextVersion",
"migrates",
"the",
"database",
"to",
"the",
"nextVersion",
".",
"If",
"the",
"database",
"is",
"already",
"at",
"nextVersion",
"or",
"higher",
"the",
"nextVersion",
"will",
"be",
"set",
"to",
"the",
"actual",
"next",
"version",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/migration/migration.go#L545-L591 |
13,444 | fabric8-services/fabric8-wit | migration/migration.go | getCurrentVersion | func getCurrentVersion(db *sql.Tx, catalog string) (int64, error) {
query := `SELECT EXISTS(
SELECT 1 FROM information_schema.tables
WHERE table_catalog=$1
AND table_name='version')`
row := db.QueryRow(query, catalog)
var exists bool
if err := row.Scan(&exists); err != nil {
return -1, errs.Errorf(`failed to scan if table "version" exists: %s\n`, err)
}
if !exists {
// table doesn't exist
return -1, nil
}
row = db.QueryRow("SELECT max(version) as current FROM version")
var current int64 = -1
if err := row.Scan(¤t); err != nil {
return -1, errs.Errorf(`failed to scan max version in table "version": %s\n`, err)
}
return current, nil
} | go | func getCurrentVersion(db *sql.Tx, catalog string) (int64, error) {
query := `SELECT EXISTS(
SELECT 1 FROM information_schema.tables
WHERE table_catalog=$1
AND table_name='version')`
row := db.QueryRow(query, catalog)
var exists bool
if err := row.Scan(&exists); err != nil {
return -1, errs.Errorf(`failed to scan if table "version" exists: %s\n`, err)
}
if !exists {
// table doesn't exist
return -1, nil
}
row = db.QueryRow("SELECT max(version) as current FROM version")
var current int64 = -1
if err := row.Scan(¤t); err != nil {
return -1, errs.Errorf(`failed to scan max version in table "version": %s\n`, err)
}
return current, nil
} | [
"func",
"getCurrentVersion",
"(",
"db",
"*",
"sql",
".",
"Tx",
",",
"catalog",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"query",
":=",
"`SELECT EXISTS(\n\t\t\t\tSELECT 1 FROM information_schema.tables\n\t\t\t\tWHERE table_catalog=$1\n\t\t\t\tAND table_name='version')`",
"\n",
"row",
":=",
"db",
".",
"QueryRow",
"(",
"query",
",",
"catalog",
")",
"\n\n",
"var",
"exists",
"bool",
"\n",
"if",
"err",
":=",
"row",
".",
"Scan",
"(",
"&",
"exists",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errs",
".",
"Errorf",
"(",
"`failed to scan if table \"version\" exists: %s\\n`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"exists",
"{",
"// table doesn't exist",
"return",
"-",
"1",
",",
"nil",
"\n",
"}",
"\n\n",
"row",
"=",
"db",
".",
"QueryRow",
"(",
"\"",
"\"",
")",
"\n\n",
"var",
"current",
"int64",
"=",
"-",
"1",
"\n",
"if",
"err",
":=",
"row",
".",
"Scan",
"(",
"&",
"current",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"errs",
".",
"Errorf",
"(",
"`failed to scan max version in table \"version\": %s\\n`",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"current",
",",
"nil",
"\n",
"}"
] | // getCurrentVersion returns the highest version from the version
// table or -1 if that table does not exist.
//
// Returning -1 simplifies the logic of the migration process because
// the next version is always the current version + 1 which results
// in -1 + 1 = 0 which is exactly what we want as the first version. | [
"getCurrentVersion",
"returns",
"the",
"highest",
"version",
"from",
"the",
"version",
"table",
"or",
"-",
"1",
"if",
"that",
"table",
"does",
"not",
"exist",
".",
"Returning",
"-",
"1",
"simplifies",
"the",
"logic",
"of",
"the",
"migration",
"process",
"because",
"the",
"next",
"version",
"is",
"always",
"the",
"current",
"version",
"+",
"1",
"which",
"results",
"in",
"-",
"1",
"+",
"1",
"=",
"0",
"which",
"is",
"exactly",
"what",
"we",
"want",
"as",
"the",
"first",
"version",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/migration/migration.go#L599-L624 |
13,445 | fabric8-services/fabric8-wit | workitem/json_storage.go | Validate | func (j *FieldDefinitions) Validate() error {
if j == nil {
return errs.New("fields not defined")
}
for name, field := range *j {
if err := field.Validate(); err != nil {
return errs.Wrapf(err, "failed to validate field %s", name)
}
}
return nil
} | go | func (j *FieldDefinitions) Validate() error {
if j == nil {
return errs.New("fields not defined")
}
for name, field := range *j {
if err := field.Validate(); err != nil {
return errs.Wrapf(err, "failed to validate field %s", name)
}
}
return nil
} | [
"func",
"(",
"j",
"*",
"FieldDefinitions",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"j",
"==",
"nil",
"{",
"return",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"name",
",",
"field",
":=",
"range",
"*",
"j",
"{",
"if",
"err",
":=",
"field",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks that each field definition is valid | [
"Validate",
"checks",
"that",
"each",
"field",
"definition",
"is",
"valid"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/json_storage.go#L73-L83 |
13,446 | fabric8-services/fabric8-wit | controller/endpoints.go | NewEndpointsController | func NewEndpointsController(service *goa.Service) *EndpointsController {
return &EndpointsController{
Controller: service.NewController("EndpointsController"),
FileHandler: workingFileFetcher{},
}
} | go | func NewEndpointsController(service *goa.Service) *EndpointsController {
return &EndpointsController{
Controller: service.NewController("EndpointsController"),
FileHandler: workingFileFetcher{},
}
} | [
"func",
"NewEndpointsController",
"(",
"service",
"*",
"goa",
".",
"Service",
")",
"*",
"EndpointsController",
"{",
"return",
"&",
"EndpointsController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"FileHandler",
":",
"workingFileFetcher",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewEndpointsController creates an endpoints controller. | [
"NewEndpointsController",
"creates",
"an",
"endpoints",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/endpoints.go#L47-L52 |
13,447 | fabric8-services/fabric8-wit | controller/endpoints.go | getEndpoints | func getEndpoints(ctx *app.ListEndpointsContext, fileHandler asseter) (*app.Endpoints, error) {
// Get an unmarshal swagger specification
swaggerJSON, err := fileHandler.Asset(embeddedSwaggerSpecFile)
if err != nil {
// TODO(tinakurian): fix error handling
return nil, errors.NewNotFoundError("file", embeddedSwaggerSpecFile)
}
var result map[string]interface{}
err = json.Unmarshal(swaggerJSON, &result)
if err != nil {
return nil, errs.Wrapf(err, `unable to unmarshal the file with id "%s"`, embeddedSwaggerSpecFile)
}
// Get and iterate over paths from swagger specification.
swaggerPaths, ok := result["paths"]
if !ok {
return nil, errors.NewInternalErrorFromString(`failed to find field "paths" in swagger specification`)
}
swaggerPathz, ok := swaggerPaths.(map[string]interface{})
if !ok {
return nil, errors.NewInternalErrorFromString(`unable to assert concrete type map for field "paths" in swagger specification`)
}
basePathObj, ok := result["basePath"]
if !ok {
return nil, errors.NewInternalErrorFromString(`failed to find field "basePath" in swagger specification`)
}
basePath, ok := basePathObj.(string)
if !ok {
return nil, errors.NewInternalErrorFromString(`unable to assert concrete type string for field "basePath" in swagger specification`)
}
absoluteBasePath := rest.AbsoluteURL(ctx.Request, basePath)
// the namedPaths map stores paths as key and URLs as values
namedPaths := make(map[string]interface{})
for path, swaggerPath := range swaggerPathz {
// Currently not supporting endpoints that contain parameters.
if !strings.Contains(path, "{") {
key := path
pathsObj, ok := swaggerPath.(map[string]interface{})
if !ok {
return nil, errors.NewInternalErrorFromString("unable to assert concrete type map for field `paths` in swagger specification")
}
// Get the x-tag value. If the tag exists, use it as path name.
xtagObj, ok := pathsObj["x-tag"]
if ok {
xtag, ok := xtagObj.(string)
if !ok {
return nil, errors.NewInternalErrorFromString("unable to assert concrete type string for field `x-tag` in swagger specification")
}
key = xtag
}
// cleanup the key to conform to JSONAPI member names
key = jsonapi.FormatMemberName(key)
// Set the related field and link objects for each name.
if key != "" {
namedPaths[key] = map[string]interface{}{
"links": map[string]string{
"related": absoluteBasePath + path,
},
}
}
}
}
return &app.Endpoints{
Type: "endpoints",
ID: uuid.NewV4(),
Relationships: namedPaths,
Links: &app.GenericLinks{
Self: ptr.String(absoluteBasePath),
},
}, nil
} | go | func getEndpoints(ctx *app.ListEndpointsContext, fileHandler asseter) (*app.Endpoints, error) {
// Get an unmarshal swagger specification
swaggerJSON, err := fileHandler.Asset(embeddedSwaggerSpecFile)
if err != nil {
// TODO(tinakurian): fix error handling
return nil, errors.NewNotFoundError("file", embeddedSwaggerSpecFile)
}
var result map[string]interface{}
err = json.Unmarshal(swaggerJSON, &result)
if err != nil {
return nil, errs.Wrapf(err, `unable to unmarshal the file with id "%s"`, embeddedSwaggerSpecFile)
}
// Get and iterate over paths from swagger specification.
swaggerPaths, ok := result["paths"]
if !ok {
return nil, errors.NewInternalErrorFromString(`failed to find field "paths" in swagger specification`)
}
swaggerPathz, ok := swaggerPaths.(map[string]interface{})
if !ok {
return nil, errors.NewInternalErrorFromString(`unable to assert concrete type map for field "paths" in swagger specification`)
}
basePathObj, ok := result["basePath"]
if !ok {
return nil, errors.NewInternalErrorFromString(`failed to find field "basePath" in swagger specification`)
}
basePath, ok := basePathObj.(string)
if !ok {
return nil, errors.NewInternalErrorFromString(`unable to assert concrete type string for field "basePath" in swagger specification`)
}
absoluteBasePath := rest.AbsoluteURL(ctx.Request, basePath)
// the namedPaths map stores paths as key and URLs as values
namedPaths := make(map[string]interface{})
for path, swaggerPath := range swaggerPathz {
// Currently not supporting endpoints that contain parameters.
if !strings.Contains(path, "{") {
key := path
pathsObj, ok := swaggerPath.(map[string]interface{})
if !ok {
return nil, errors.NewInternalErrorFromString("unable to assert concrete type map for field `paths` in swagger specification")
}
// Get the x-tag value. If the tag exists, use it as path name.
xtagObj, ok := pathsObj["x-tag"]
if ok {
xtag, ok := xtagObj.(string)
if !ok {
return nil, errors.NewInternalErrorFromString("unable to assert concrete type string for field `x-tag` in swagger specification")
}
key = xtag
}
// cleanup the key to conform to JSONAPI member names
key = jsonapi.FormatMemberName(key)
// Set the related field and link objects for each name.
if key != "" {
namedPaths[key] = map[string]interface{}{
"links": map[string]string{
"related": absoluteBasePath + path,
},
}
}
}
}
return &app.Endpoints{
Type: "endpoints",
ID: uuid.NewV4(),
Relationships: namedPaths,
Links: &app.GenericLinks{
Self: ptr.String(absoluteBasePath),
},
}, nil
} | [
"func",
"getEndpoints",
"(",
"ctx",
"*",
"app",
".",
"ListEndpointsContext",
",",
"fileHandler",
"asseter",
")",
"(",
"*",
"app",
".",
"Endpoints",
",",
"error",
")",
"{",
"// Get an unmarshal swagger specification",
"swaggerJSON",
",",
"err",
":=",
"fileHandler",
".",
"Asset",
"(",
"embeddedSwaggerSpecFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO(tinakurian): fix error handling",
"return",
"nil",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"embeddedSwaggerSpecFile",
")",
"\n",
"}",
"\n\n",
"var",
"result",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"swaggerJSON",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"`unable to unmarshal the file with id \"%s\"`",
",",
"embeddedSwaggerSpecFile",
")",
"\n",
"}",
"\n\n",
"// Get and iterate over paths from swagger specification.",
"swaggerPaths",
",",
"ok",
":=",
"result",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"`failed to find field \"paths\" in swagger specification`",
")",
"\n",
"}",
"\n\n",
"swaggerPathz",
",",
"ok",
":=",
"swaggerPaths",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"`unable to assert concrete type map for field \"paths\" in swagger specification`",
")",
"\n",
"}",
"\n\n",
"basePathObj",
",",
"ok",
":=",
"result",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"`failed to find field \"basePath\" in swagger specification`",
")",
"\n",
"}",
"\n\n",
"basePath",
",",
"ok",
":=",
"basePathObj",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"`unable to assert concrete type string for field \"basePath\" in swagger specification`",
")",
"\n",
"}",
"\n\n",
"absoluteBasePath",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"ctx",
".",
"Request",
",",
"basePath",
")",
"\n\n",
"// the namedPaths map stores paths as key and URLs as values",
"namedPaths",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"path",
",",
"swaggerPath",
":=",
"range",
"swaggerPathz",
"{",
"// Currently not supporting endpoints that contain parameters.",
"if",
"!",
"strings",
".",
"Contains",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"key",
":=",
"path",
"\n\n",
"pathsObj",
",",
"ok",
":=",
"swaggerPath",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Get the x-tag value. If the tag exists, use it as path name.",
"xtagObj",
",",
"ok",
":=",
"pathsObj",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"ok",
"{",
"xtag",
",",
"ok",
":=",
"xtagObj",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"NewInternalErrorFromString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"key",
"=",
"xtag",
"\n",
"}",
"\n\n",
"// cleanup the key to conform to JSONAPI member names",
"key",
"=",
"jsonapi",
".",
"FormatMemberName",
"(",
"key",
")",
"\n\n",
"// Set the related field and link objects for each name.",
"if",
"key",
"!=",
"\"",
"\"",
"{",
"namedPaths",
"[",
"key",
"]",
"=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"absoluteBasePath",
"+",
"path",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"app",
".",
"Endpoints",
"{",
"Type",
":",
"\"",
"\"",
",",
"ID",
":",
"uuid",
".",
"NewV4",
"(",
")",
",",
"Relationships",
":",
"namedPaths",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"ptr",
".",
"String",
"(",
"absoluteBasePath",
")",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Get a list of all endpoints formatted to json api format. | [
"Get",
"a",
"list",
"of",
"all",
"endpoints",
"formatted",
"to",
"json",
"api",
"format",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/endpoints.go#L73-L156 |
13,448 | fabric8-services/fabric8-wit | controller/deployments_urlprovider.go | NewURLProvider | func NewURLProvider(ctx context.Context, config *configuration.Registry, osioclient OpenshiftIOClient) (kubernetes.BaseURLProvider, error) {
userServices, err := osioclient.GetUserServices(ctx)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error accessing Tenant API")
return nil, err
}
token := goajwt.ContextJWT(ctx).Raw
proxyURL := config.GetOpenshiftProxyURL()
up, err := newTenantURLProviderFromTenant(userServices, token, proxyURL)
if err != nil {
return nil, err
}
// create Auth API client - required to get OSO tokens
authClient, err := auth.CreateClient(ctx, config)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error accessing Auth server")
return nil, errs.Wrap(err, "error creating Auth client")
}
up.TokenRetriever = &tokenRetriever{
authClient: authClient,
context: ctx,
}
// if we're not using a proxy then the API URL is actually the cluster of namespace 0,
// so the apiToken should be the token for that cluster.
// there should be no defaults, but that's deferred later
if len(proxyURL) == 0 {
tokenData, err := up.TokenForService(up.apiURL)
if err != nil {
return nil, err
}
up.apiToken = *tokenData
}
return up, nil
} | go | func NewURLProvider(ctx context.Context, config *configuration.Registry, osioclient OpenshiftIOClient) (kubernetes.BaseURLProvider, error) {
userServices, err := osioclient.GetUserServices(ctx)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error accessing Tenant API")
return nil, err
}
token := goajwt.ContextJWT(ctx).Raw
proxyURL := config.GetOpenshiftProxyURL()
up, err := newTenantURLProviderFromTenant(userServices, token, proxyURL)
if err != nil {
return nil, err
}
// create Auth API client - required to get OSO tokens
authClient, err := auth.CreateClient(ctx, config)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "error accessing Auth server")
return nil, errs.Wrap(err, "error creating Auth client")
}
up.TokenRetriever = &tokenRetriever{
authClient: authClient,
context: ctx,
}
// if we're not using a proxy then the API URL is actually the cluster of namespace 0,
// so the apiToken should be the token for that cluster.
// there should be no defaults, but that's deferred later
if len(proxyURL) == 0 {
tokenData, err := up.TokenForService(up.apiURL)
if err != nil {
return nil, err
}
up.apiToken = *tokenData
}
return up, nil
} | [
"func",
"NewURLProvider",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"*",
"configuration",
".",
"Registry",
",",
"osioclient",
"OpenshiftIOClient",
")",
"(",
"kubernetes",
".",
"BaseURLProvider",
",",
"error",
")",
"{",
"userServices",
",",
"err",
":=",
"osioclient",
".",
"GetUserServices",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"token",
":=",
"goajwt",
".",
"ContextJWT",
"(",
"ctx",
")",
".",
"Raw",
"\n",
"proxyURL",
":=",
"config",
".",
"GetOpenshiftProxyURL",
"(",
")",
"\n\n",
"up",
",",
"err",
":=",
"newTenantURLProviderFromTenant",
"(",
"userServices",
",",
"token",
",",
"proxyURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// create Auth API client - required to get OSO tokens",
"authClient",
",",
"err",
":=",
"auth",
".",
"CreateClient",
"(",
"ctx",
",",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"up",
".",
"TokenRetriever",
"=",
"&",
"tokenRetriever",
"{",
"authClient",
":",
"authClient",
",",
"context",
":",
"ctx",
",",
"}",
"\n\n",
"// if we're not using a proxy then the API URL is actually the cluster of namespace 0,",
"// so the apiToken should be the token for that cluster.",
"// there should be no defaults, but that's deferred later",
"if",
"len",
"(",
"proxyURL",
")",
"==",
"0",
"{",
"tokenData",
",",
"err",
":=",
"up",
".",
"TokenForService",
"(",
"up",
".",
"apiURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"up",
".",
"apiToken",
"=",
"*",
"tokenData",
"\n",
"}",
"\n",
"return",
"up",
",",
"nil",
"\n",
"}"
] | // NewURLProvider looks at what servers are available and create a BaseURLProvder that fits | [
"NewURLProvider",
"looks",
"at",
"what",
"servers",
"are",
"available",
"and",
"create",
"a",
"BaseURLProvder",
"that",
"fits"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments_urlprovider.go#L92-L134 |
13,449 | fabric8-services/fabric8-wit | controller/deployments_urlprovider.go | newTenantURLProviderFromTenant | func newTenantURLProviderFromTenant(t *app.UserService, token string, proxyURL string) (*tenantURLProvider, error) {
if t.ID == nil {
log.Error(nil, map[string]interface{}{}, "app.UserService is malformed: no ID field")
return nil, errs.New("app.UserService is malformed: no ID field")
}
if t.Attributes == nil {
log.Error(nil, map[string]interface{}{
"tenant": *t.ID,
}, "app.UserService is malformed: no Attribute field ID=%s", *t.ID)
return nil, errs.Errorf("app.UserService is malformed: no Attribute field (ID=%s)", *t.ID)
}
if len(t.Attributes.Namespaces) == 0 {
log.Error(nil, map[string]interface{}{
"tenant": *t.ID,
}, "this tenant has no namespaces: %s", *t.ID)
return nil, errs.Errorf("app.UserService is malformed: no Namespaces (ID=%s)", *t.ID)
}
defaultNamespace := t.Attributes.Namespaces[0]
namespaceMap := make(map[string]*app.NamespaceAttributes)
for i, namespace := range t.Attributes.Namespaces {
namespaceMap[*namespace.Name] = t.Attributes.Namespaces[i]
if namespace.Type != nil && *namespace.Type == "user" {
defaultNamespace = namespace
}
}
defaultClusterURL := *defaultNamespace.ClusterURL
if len(proxyURL) != 0 {
// all non-metric API calls go via the proxy
defaultClusterURL = proxyURL
}
provider := &tenantURLProvider{
apiURL: defaultClusterURL,
apiToken: token,
tenant: t,
namespaces: namespaceMap,
}
return provider, nil
} | go | func newTenantURLProviderFromTenant(t *app.UserService, token string, proxyURL string) (*tenantURLProvider, error) {
if t.ID == nil {
log.Error(nil, map[string]interface{}{}, "app.UserService is malformed: no ID field")
return nil, errs.New("app.UserService is malformed: no ID field")
}
if t.Attributes == nil {
log.Error(nil, map[string]interface{}{
"tenant": *t.ID,
}, "app.UserService is malformed: no Attribute field ID=%s", *t.ID)
return nil, errs.Errorf("app.UserService is malformed: no Attribute field (ID=%s)", *t.ID)
}
if len(t.Attributes.Namespaces) == 0 {
log.Error(nil, map[string]interface{}{
"tenant": *t.ID,
}, "this tenant has no namespaces: %s", *t.ID)
return nil, errs.Errorf("app.UserService is malformed: no Namespaces (ID=%s)", *t.ID)
}
defaultNamespace := t.Attributes.Namespaces[0]
namespaceMap := make(map[string]*app.NamespaceAttributes)
for i, namespace := range t.Attributes.Namespaces {
namespaceMap[*namespace.Name] = t.Attributes.Namespaces[i]
if namespace.Type != nil && *namespace.Type == "user" {
defaultNamespace = namespace
}
}
defaultClusterURL := *defaultNamespace.ClusterURL
if len(proxyURL) != 0 {
// all non-metric API calls go via the proxy
defaultClusterURL = proxyURL
}
provider := &tenantURLProvider{
apiURL: defaultClusterURL,
apiToken: token,
tenant: t,
namespaces: namespaceMap,
}
return provider, nil
} | [
"func",
"newTenantURLProviderFromTenant",
"(",
"t",
"*",
"app",
".",
"UserService",
",",
"token",
"string",
",",
"proxyURL",
"string",
")",
"(",
"*",
"tenantURLProvider",
",",
"error",
")",
"{",
"if",
"t",
".",
"ID",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"Attributes",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"*",
"t",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
",",
"*",
"t",
".",
"ID",
")",
"\n",
"return",
"nil",
",",
"errs",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"t",
".",
"ID",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"t",
".",
"Attributes",
".",
"Namespaces",
")",
"==",
"0",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"*",
"t",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
",",
"*",
"t",
".",
"ID",
")",
"\n",
"return",
"nil",
",",
"errs",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"*",
"t",
".",
"ID",
")",
"\n",
"}",
"\n\n",
"defaultNamespace",
":=",
"t",
".",
"Attributes",
".",
"Namespaces",
"[",
"0",
"]",
"\n",
"namespaceMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"app",
".",
"NamespaceAttributes",
")",
"\n",
"for",
"i",
",",
"namespace",
":=",
"range",
"t",
".",
"Attributes",
".",
"Namespaces",
"{",
"namespaceMap",
"[",
"*",
"namespace",
".",
"Name",
"]",
"=",
"t",
".",
"Attributes",
".",
"Namespaces",
"[",
"i",
"]",
"\n",
"if",
"namespace",
".",
"Type",
"!=",
"nil",
"&&",
"*",
"namespace",
".",
"Type",
"==",
"\"",
"\"",
"{",
"defaultNamespace",
"=",
"namespace",
"\n",
"}",
"\n",
"}",
"\n\n",
"defaultClusterURL",
":=",
"*",
"defaultNamespace",
".",
"ClusterURL",
"\n\n",
"if",
"len",
"(",
"proxyURL",
")",
"!=",
"0",
"{",
"// all non-metric API calls go via the proxy",
"defaultClusterURL",
"=",
"proxyURL",
"\n",
"}",
"\n\n",
"provider",
":=",
"&",
"tenantURLProvider",
"{",
"apiURL",
":",
"defaultClusterURL",
",",
"apiToken",
":",
"token",
",",
"tenant",
":",
"t",
",",
"namespaces",
":",
"namespaceMap",
",",
"}",
"\n",
"return",
"provider",
",",
"nil",
"\n",
"}"
] | // newTenantURLProviderFromTenant create a provider from a UserService object | [
"newTenantURLProviderFromTenant",
"create",
"a",
"provider",
"from",
"a",
"UserService",
"object"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments_urlprovider.go#L137-L181 |
13,450 | fabric8-services/fabric8-wit | controller/deployments_urlprovider.go | GetEnvironmentMapping | func (up *tenantURLProvider) GetEnvironmentMapping() map[string]string {
result := make(map[string]string)
// Exclude internal namespaces where the user cannot deploy applications
// Deployments API will receive requests by environment name (e.g. "run", "stage").
// These names correspond to the "type" attribute in Namespaces.
for envNS, attr := range up.namespaces {
envName := attr.Type
if envName == nil || len(*envName) == 0 {
log.Error(nil, map[string]interface{}{
"namespace": envNS,
}, "namespace has no type")
} else {
result[*envName] = envNS
}
}
return result
} | go | func (up *tenantURLProvider) GetEnvironmentMapping() map[string]string {
result := make(map[string]string)
// Exclude internal namespaces where the user cannot deploy applications
// Deployments API will receive requests by environment name (e.g. "run", "stage").
// These names correspond to the "type" attribute in Namespaces.
for envNS, attr := range up.namespaces {
envName := attr.Type
if envName == nil || len(*envName) == 0 {
log.Error(nil, map[string]interface{}{
"namespace": envNS,
}, "namespace has no type")
} else {
result[*envName] = envNS
}
}
return result
} | [
"func",
"(",
"up",
"*",
"tenantURLProvider",
")",
"GetEnvironmentMapping",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"// Exclude internal namespaces where the user cannot deploy applications",
"// Deployments API will receive requests by environment name (e.g. \"run\", \"stage\").",
"// These names correspond to the \"type\" attribute in Namespaces.",
"for",
"envNS",
",",
"attr",
":=",
"range",
"up",
".",
"namespaces",
"{",
"envName",
":=",
"attr",
".",
"Type",
"\n",
"if",
"envName",
"==",
"nil",
"||",
"len",
"(",
"*",
"envName",
")",
"==",
"0",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"envNS",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"result",
"[",
"*",
"envName",
"]",
"=",
"envNS",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // GetEnvironmentMapping returns a map whose keys are environment names, and values are the Kubernetes namespaces
// that represent those environments | [
"GetEnvironmentMapping",
"returns",
"a",
"map",
"whose",
"keys",
"are",
"environment",
"names",
"and",
"values",
"are",
"the",
"Kubernetes",
"namespaces",
"that",
"represent",
"those",
"environments"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments_urlprovider.go#L190-L207 |
13,451 | fabric8-services/fabric8-wit | controller/deployments_urlprovider.go | CanDeploy | func (up *tenantURLProvider) CanDeploy(envType string) bool {
_, pres := internalNamespaceTypes[envType]
return !pres
} | go | func (up *tenantURLProvider) CanDeploy(envType string) bool {
_, pres := internalNamespaceTypes[envType]
return !pres
} | [
"func",
"(",
"up",
"*",
"tenantURLProvider",
")",
"CanDeploy",
"(",
"envType",
"string",
")",
"bool",
"{",
"_",
",",
"pres",
":=",
"internalNamespaceTypes",
"[",
"envType",
"]",
"\n",
"return",
"!",
"pres",
"\n",
"}"
] | // CanDeploy returns true if the environment type provided can be deployed to as part of a pipeline | [
"CanDeploy",
"returns",
"true",
"if",
"the",
"environment",
"type",
"provided",
"can",
"be",
"deployed",
"to",
"as",
"part",
"of",
"a",
"pipeline"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/deployments_urlprovider.go#L213-L216 |
13,452 | fabric8-services/fabric8-wit | controller/features.go | NewFeaturesController | func NewFeaturesController(service *goa.Service, config FeaturesControllerConfiguration) *FeaturesController {
return &FeaturesController{
Controller: service.NewController("FeaturesController"),
config: config,
}
} | go | func NewFeaturesController(service *goa.Service, config FeaturesControllerConfiguration) *FeaturesController {
return &FeaturesController{
Controller: service.NewController("FeaturesController"),
config: config,
}
} | [
"func",
"NewFeaturesController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"config",
"FeaturesControllerConfiguration",
")",
"*",
"FeaturesController",
"{",
"return",
"&",
"FeaturesController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"config",
":",
"config",
",",
"}",
"\n",
"}"
] | // NewFeaturesController creates a features controller. | [
"NewFeaturesController",
"creates",
"a",
"features",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/features.go#L21-L26 |
13,453 | fabric8-services/fabric8-wit | controller/area.go | NewAreaController | func NewAreaController(service *goa.Service, db application.DB, config AreaControllerConfiguration) *AreaController {
return &AreaController{
Controller: service.NewController("AreaController"),
db: db,
config: config}
} | go | func NewAreaController(service *goa.Service, db application.DB, config AreaControllerConfiguration) *AreaController {
return &AreaController{
Controller: service.NewController("AreaController"),
db: db,
config: config}
} | [
"func",
"NewAreaController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
",",
"config",
"AreaControllerConfiguration",
")",
"*",
"AreaController",
"{",
"return",
"&",
"AreaController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
",",
"config",
":",
"config",
"}",
"\n",
"}"
] | // NewAreaController creates a area controller. | [
"NewAreaController",
"creates",
"a",
"area",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/area.go#L40-L45 |
13,454 | fabric8-services/fabric8-wit | controller/area.go | ShowChildren | func (c *AreaController) ShowChildren(ctx *app.ShowChildrenAreaContext) error {
id, err := uuid.FromString(ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
var children []area.Area
err = application.Transactional(c.db, func(appl application.Application) error {
parentArea, err := appl.Areas().Load(ctx, id)
if err != nil {
return err
}
children, err = appl.Areas().ListChildren(ctx, parentArea)
return err
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.ConditionalEntities(children, c.config.GetCacheControlAreas, func() error {
res := &app.AreaList{}
res.Data = ConvertAreas(c.db, ctx.Request, children, addResolvedPath)
return ctx.OK(res)
})
} | go | func (c *AreaController) ShowChildren(ctx *app.ShowChildrenAreaContext) error {
id, err := uuid.FromString(ctx.ID)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrNotFound(err.Error()))
}
var children []area.Area
err = application.Transactional(c.db, func(appl application.Application) error {
parentArea, err := appl.Areas().Load(ctx, id)
if err != nil {
return err
}
children, err = appl.Areas().ListChildren(ctx, parentArea)
return err
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.ConditionalEntities(children, c.config.GetCacheControlAreas, func() error {
res := &app.AreaList{}
res.Data = ConvertAreas(c.db, ctx.Request, children, addResolvedPath)
return ctx.OK(res)
})
} | [
"func",
"(",
"c",
"*",
"AreaController",
")",
"ShowChildren",
"(",
"ctx",
"*",
"app",
".",
"ShowChildrenAreaContext",
")",
"error",
"{",
"id",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"ctx",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrNotFound",
"(",
"err",
".",
"Error",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"var",
"children",
"[",
"]",
"area",
".",
"Area",
"\n",
"err",
"=",
"application",
".",
"Transactional",
"(",
"c",
".",
"db",
",",
"func",
"(",
"appl",
"application",
".",
"Application",
")",
"error",
"{",
"parentArea",
",",
"err",
":=",
"appl",
".",
"Areas",
"(",
")",
".",
"Load",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"children",
",",
"err",
"=",
"appl",
".",
"Areas",
"(",
")",
".",
"ListChildren",
"(",
"ctx",
",",
"parentArea",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"ctx",
".",
"ConditionalEntities",
"(",
"children",
",",
"c",
".",
"config",
".",
"GetCacheControlAreas",
",",
"func",
"(",
")",
"error",
"{",
"res",
":=",
"&",
"app",
".",
"AreaList",
"{",
"}",
"\n",
"res",
".",
"Data",
"=",
"ConvertAreas",
"(",
"c",
".",
"db",
",",
"ctx",
".",
"Request",
",",
"children",
",",
"addResolvedPath",
")",
"\n",
"return",
"ctx",
".",
"OK",
"(",
"res",
")",
"\n",
"}",
")",
"\n",
"}"
] | // ShowChildren runs the show-children action | [
"ShowChildren",
"runs",
"the",
"show",
"-",
"children",
"action"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/area.go#L48-L71 |
13,455 | fabric8-services/fabric8-wit | controller/area.go | ConvertAreas | func ConvertAreas(db application.DB, request *http.Request, areas []area.Area, additional ...AreaConvertFunc) []*app.Area {
var is = []*app.Area{}
for _, i := range areas {
is = append(is, ConvertArea(db, request, i, additional...))
}
return is
} | go | func ConvertAreas(db application.DB, request *http.Request, areas []area.Area, additional ...AreaConvertFunc) []*app.Area {
var is = []*app.Area{}
for _, i := range areas {
is = append(is, ConvertArea(db, request, i, additional...))
}
return is
} | [
"func",
"ConvertAreas",
"(",
"db",
"application",
".",
"DB",
",",
"request",
"*",
"http",
".",
"Request",
",",
"areas",
"[",
"]",
"area",
".",
"Area",
",",
"additional",
"...",
"AreaConvertFunc",
")",
"[",
"]",
"*",
"app",
".",
"Area",
"{",
"var",
"is",
"=",
"[",
"]",
"*",
"app",
".",
"Area",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"areas",
"{",
"is",
"=",
"append",
"(",
"is",
",",
"ConvertArea",
"(",
"db",
",",
"request",
",",
"i",
",",
"additional",
"...",
")",
")",
"\n",
"}",
"\n",
"return",
"is",
"\n",
"}"
] | // ConvertAreas converts between internal and external REST representation | [
"ConvertAreas",
"converts",
"between",
"internal",
"and",
"external",
"REST",
"representation"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/area.go#L193-L199 |
13,456 | fabric8-services/fabric8-wit | controller/area.go | ConvertArea | func ConvertArea(db application.DB, request *http.Request, ar area.Area, options ...AreaConvertFunc) *app.Area {
relatedURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID))
childURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID)+"/children")
spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(ar.SpaceID))
i := &app.Area{
Type: area.APIStringTypeAreas,
ID: &ar.ID,
Attributes: &app.AreaAttributes{
Name: &ar.Name,
CreatedAt: &ar.CreatedAt,
UpdatedAt: &ar.UpdatedAt,
Version: &ar.Version,
ParentPath: ptr.String(ar.Path.ParentPath().String()),
Number: &ar.Number,
},
Relationships: &app.AreaRelations{
Space: &app.RelationGeneric{
Data: &app.GenericData{
Type: &space.SpaceType,
ID: ptr.String(ar.SpaceID.String()),
},
Links: &app.GenericLinks{
Self: &spaceRelatedURL,
Related: &spaceRelatedURL,
},
},
Children: &app.RelationGeneric{
Links: &app.GenericLinks{
Self: &childURL,
Related: &childURL,
},
},
},
Links: &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
},
}
// Now check the path, if the path is empty, then this is the topmost area
// in a specific space.
if !ar.Path.ParentPath().IsEmpty() {
parent := ar.Path.ParentID().String()
i.Relationships.Parent = &app.RelationGeneric{
Data: &app.GenericData{
Type: ptr.String(area.APIStringTypeAreas),
ID: &parent,
},
Links: &app.GenericLinks{
// Only the immediate parent's URL.
Self: ptr.String(rest.AbsoluteURL(request, app.AreaHref(parent))),
},
}
}
for _, opt := range options {
opt(db, request, &ar, i)
}
return i
} | go | func ConvertArea(db application.DB, request *http.Request, ar area.Area, options ...AreaConvertFunc) *app.Area {
relatedURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID))
childURL := rest.AbsoluteURL(request, app.AreaHref(ar.ID)+"/children")
spaceRelatedURL := rest.AbsoluteURL(request, app.SpaceHref(ar.SpaceID))
i := &app.Area{
Type: area.APIStringTypeAreas,
ID: &ar.ID,
Attributes: &app.AreaAttributes{
Name: &ar.Name,
CreatedAt: &ar.CreatedAt,
UpdatedAt: &ar.UpdatedAt,
Version: &ar.Version,
ParentPath: ptr.String(ar.Path.ParentPath().String()),
Number: &ar.Number,
},
Relationships: &app.AreaRelations{
Space: &app.RelationGeneric{
Data: &app.GenericData{
Type: &space.SpaceType,
ID: ptr.String(ar.SpaceID.String()),
},
Links: &app.GenericLinks{
Self: &spaceRelatedURL,
Related: &spaceRelatedURL,
},
},
Children: &app.RelationGeneric{
Links: &app.GenericLinks{
Self: &childURL,
Related: &childURL,
},
},
},
Links: &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
},
}
// Now check the path, if the path is empty, then this is the topmost area
// in a specific space.
if !ar.Path.ParentPath().IsEmpty() {
parent := ar.Path.ParentID().String()
i.Relationships.Parent = &app.RelationGeneric{
Data: &app.GenericData{
Type: ptr.String(area.APIStringTypeAreas),
ID: &parent,
},
Links: &app.GenericLinks{
// Only the immediate parent's URL.
Self: ptr.String(rest.AbsoluteURL(request, app.AreaHref(parent))),
},
}
}
for _, opt := range options {
opt(db, request, &ar, i)
}
return i
} | [
"func",
"ConvertArea",
"(",
"db",
"application",
".",
"DB",
",",
"request",
"*",
"http",
".",
"Request",
",",
"ar",
"area",
".",
"Area",
",",
"options",
"...",
"AreaConvertFunc",
")",
"*",
"app",
".",
"Area",
"{",
"relatedURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"AreaHref",
"(",
"ar",
".",
"ID",
")",
")",
"\n",
"childURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"AreaHref",
"(",
"ar",
".",
"ID",
")",
"+",
"\"",
"\"",
")",
"\n",
"spaceRelatedURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"SpaceHref",
"(",
"ar",
".",
"SpaceID",
")",
")",
"\n",
"i",
":=",
"&",
"app",
".",
"Area",
"{",
"Type",
":",
"area",
".",
"APIStringTypeAreas",
",",
"ID",
":",
"&",
"ar",
".",
"ID",
",",
"Attributes",
":",
"&",
"app",
".",
"AreaAttributes",
"{",
"Name",
":",
"&",
"ar",
".",
"Name",
",",
"CreatedAt",
":",
"&",
"ar",
".",
"CreatedAt",
",",
"UpdatedAt",
":",
"&",
"ar",
".",
"UpdatedAt",
",",
"Version",
":",
"&",
"ar",
".",
"Version",
",",
"ParentPath",
":",
"ptr",
".",
"String",
"(",
"ar",
".",
"Path",
".",
"ParentPath",
"(",
")",
".",
"String",
"(",
")",
")",
",",
"Number",
":",
"&",
"ar",
".",
"Number",
",",
"}",
",",
"Relationships",
":",
"&",
"app",
".",
"AreaRelations",
"{",
"Space",
":",
"&",
"app",
".",
"RelationGeneric",
"{",
"Data",
":",
"&",
"app",
".",
"GenericData",
"{",
"Type",
":",
"&",
"space",
".",
"SpaceType",
",",
"ID",
":",
"ptr",
".",
"String",
"(",
"ar",
".",
"SpaceID",
".",
"String",
"(",
")",
")",
",",
"}",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"&",
"spaceRelatedURL",
",",
"Related",
":",
"&",
"spaceRelatedURL",
",",
"}",
",",
"}",
",",
"Children",
":",
"&",
"app",
".",
"RelationGeneric",
"{",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"&",
"childURL",
",",
"Related",
":",
"&",
"childURL",
",",
"}",
",",
"}",
",",
"}",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"&",
"relatedURL",
",",
"Related",
":",
"&",
"relatedURL",
",",
"}",
",",
"}",
"\n\n",
"// Now check the path, if the path is empty, then this is the topmost area",
"// in a specific space.",
"if",
"!",
"ar",
".",
"Path",
".",
"ParentPath",
"(",
")",
".",
"IsEmpty",
"(",
")",
"{",
"parent",
":=",
"ar",
".",
"Path",
".",
"ParentID",
"(",
")",
".",
"String",
"(",
")",
"\n",
"i",
".",
"Relationships",
".",
"Parent",
"=",
"&",
"app",
".",
"RelationGeneric",
"{",
"Data",
":",
"&",
"app",
".",
"GenericData",
"{",
"Type",
":",
"ptr",
".",
"String",
"(",
"area",
".",
"APIStringTypeAreas",
")",
",",
"ID",
":",
"&",
"parent",
",",
"}",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"// Only the immediate parent's URL.",
"Self",
":",
"ptr",
".",
"String",
"(",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"AreaHref",
"(",
"parent",
")",
")",
")",
",",
"}",
",",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"options",
"{",
"opt",
"(",
"db",
",",
"request",
",",
"&",
"ar",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"i",
"\n",
"}"
] | // ConvertArea converts between internal and external REST representation | [
"ConvertArea",
"converts",
"between",
"internal",
"and",
"external",
"REST",
"representation"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/area.go#L202-L260 |
13,457 | fabric8-services/fabric8-wit | controller/area.go | ConvertAreaSimple | func ConvertAreaSimple(request *http.Request, id interface{}) (*app.GenericData, *app.GenericLinks) {
t := area.APIStringTypeAreas
i := fmt.Sprint(id)
data := &app.GenericData{
Type: &t,
ID: &i,
}
relatedURL := rest.AbsoluteURL(request, app.AreaHref(i))
links := &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
}
return data, links
} | go | func ConvertAreaSimple(request *http.Request, id interface{}) (*app.GenericData, *app.GenericLinks) {
t := area.APIStringTypeAreas
i := fmt.Sprint(id)
data := &app.GenericData{
Type: &t,
ID: &i,
}
relatedURL := rest.AbsoluteURL(request, app.AreaHref(i))
links := &app.GenericLinks{
Self: &relatedURL,
Related: &relatedURL,
}
return data, links
} | [
"func",
"ConvertAreaSimple",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"id",
"interface",
"{",
"}",
")",
"(",
"*",
"app",
".",
"GenericData",
",",
"*",
"app",
".",
"GenericLinks",
")",
"{",
"t",
":=",
"area",
".",
"APIStringTypeAreas",
"\n",
"i",
":=",
"fmt",
".",
"Sprint",
"(",
"id",
")",
"\n",
"data",
":=",
"&",
"app",
".",
"GenericData",
"{",
"Type",
":",
"&",
"t",
",",
"ID",
":",
"&",
"i",
",",
"}",
"\n",
"relatedURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"AreaHref",
"(",
"i",
")",
")",
"\n",
"links",
":=",
"&",
"app",
".",
"GenericLinks",
"{",
"Self",
":",
"&",
"relatedURL",
",",
"Related",
":",
"&",
"relatedURL",
",",
"}",
"\n",
"return",
"data",
",",
"links",
"\n",
"}"
] | // ConvertAreaSimple converts a simple area ID into a Generic Relationship
// data+links element | [
"ConvertAreaSimple",
"converts",
"a",
"simple",
"area",
"ID",
"into",
"a",
"Generic",
"Relationship",
"data",
"+",
"links",
"element"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/area.go#L264-L277 |
13,458 | fabric8-services/fabric8-wit | controller/work_item_type_group.go | NewWorkItemTypeGroupController | func NewWorkItemTypeGroupController(service *goa.Service, db application.DB) *WorkItemTypeGroupController {
return &WorkItemTypeGroupController{
Controller: service.NewController("WorkItemTypeGroupController"),
db: db,
}
} | go | func NewWorkItemTypeGroupController(service *goa.Service, db application.DB) *WorkItemTypeGroupController {
return &WorkItemTypeGroupController{
Controller: service.NewController("WorkItemTypeGroupController"),
db: db,
}
} | [
"func",
"NewWorkItemTypeGroupController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
")",
"*",
"WorkItemTypeGroupController",
"{",
"return",
"&",
"WorkItemTypeGroupController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
",",
"}",
"\n",
"}"
] | // NewWorkItemTypeGroupController creates a work_item_type_group controller. | [
"NewWorkItemTypeGroupController",
"creates",
"a",
"work_item_type_group",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_type_group.go#L27-L32 |
13,459 | fabric8-services/fabric8-wit | controller/work_item_type_group.go | Show | func (c *WorkItemTypeGroupController) Show(ctx *app.ShowWorkItemTypeGroupContext) error {
var typeGroup *workitem.WorkItemTypeGroup
var err error
err = application.Transactional(c.db, func(appl application.Application) error {
typeGroup, err = appl.WorkItemTypeGroups().Load(ctx, ctx.GroupID)
if err != nil {
return errs.WithStack(err)
}
return nil
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(&app.WorkItemTypeGroupSingle{
Data: ConvertTypeGroup(ctx.Request, *typeGroup),
})
} | go | func (c *WorkItemTypeGroupController) Show(ctx *app.ShowWorkItemTypeGroupContext) error {
var typeGroup *workitem.WorkItemTypeGroup
var err error
err = application.Transactional(c.db, func(appl application.Application) error {
typeGroup, err = appl.WorkItemTypeGroups().Load(ctx, ctx.GroupID)
if err != nil {
return errs.WithStack(err)
}
return nil
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(&app.WorkItemTypeGroupSingle{
Data: ConvertTypeGroup(ctx.Request, *typeGroup),
})
} | [
"func",
"(",
"c",
"*",
"WorkItemTypeGroupController",
")",
"Show",
"(",
"ctx",
"*",
"app",
".",
"ShowWorkItemTypeGroupContext",
")",
"error",
"{",
"var",
"typeGroup",
"*",
"workitem",
".",
"WorkItemTypeGroup",
"\n",
"var",
"err",
"error",
"\n",
"err",
"=",
"application",
".",
"Transactional",
"(",
"c",
".",
"db",
",",
"func",
"(",
"appl",
"application",
".",
"Application",
")",
"error",
"{",
"typeGroup",
",",
"err",
"=",
"appl",
".",
"WorkItemTypeGroups",
"(",
")",
".",
"Load",
"(",
"ctx",
",",
"ctx",
".",
"GroupID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"OK",
"(",
"&",
"app",
".",
"WorkItemTypeGroupSingle",
"{",
"Data",
":",
"ConvertTypeGroup",
"(",
"ctx",
".",
"Request",
",",
"*",
"typeGroup",
")",
",",
"}",
")",
"\n",
"}"
] | // Show runs the list action. | [
"Show",
"runs",
"the",
"list",
"action",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_type_group.go#L35-L51 |
13,460 | fabric8-services/fabric8-wit | controller/work_item_type_group.go | ConvertTypeGroup | func ConvertTypeGroup(request *http.Request, tg workitem.WorkItemTypeGroup) *app.WorkItemTypeGroupData {
workitemtypes := "workitemtypes"
workItemTypeGroupRelatedURL := rest.AbsoluteURL(request, app.WorkItemTypeGroupHref(tg.ID))
createdAt := tg.CreatedAt.UTC()
updatedAt := tg.UpdatedAt.UTC()
// Every work item type group except the one in the "iteration" bucket are
// meant to be shown in the sidebar.
showInSidebar := (tg.Bucket != workitem.BucketIteration)
res := &app.WorkItemTypeGroupData{
ID: &tg.ID,
Type: APIWorkItemTypeGroups,
Links: &app.GenericLinks{
Related: &workItemTypeGroupRelatedURL,
},
Attributes: &app.WorkItemTypeGroupAttributes{
Bucket: tg.Bucket.String(),
Name: tg.Name,
Description: tg.Description,
Icon: tg.Icon,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
ShowInSidebar: &showInSidebar,
},
Relationships: &app.WorkItemTypeGroupRelationships{
TypeList: &app.RelationGenericList{
Data: make([]*app.GenericData, len(tg.TypeList)),
},
SpaceTemplate: &app.RelationGeneric{
Data: &app.GenericData{
ID: ptr.String(tg.SpaceTemplateID.String()),
Type: &APISpaceTemplates,
},
},
},
}
for i, witID := range tg.TypeList {
// witRelatedURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(space.SystemSpace, witID))
idStr := witID.String()
res.Relationships.TypeList.Data[i] = &app.GenericData{
ID: &idStr,
Type: &workitemtypes,
// Links: &app.GenericLinks{
// Related: &witRelatedURL,
// },
}
}
return res
} | go | func ConvertTypeGroup(request *http.Request, tg workitem.WorkItemTypeGroup) *app.WorkItemTypeGroupData {
workitemtypes := "workitemtypes"
workItemTypeGroupRelatedURL := rest.AbsoluteURL(request, app.WorkItemTypeGroupHref(tg.ID))
createdAt := tg.CreatedAt.UTC()
updatedAt := tg.UpdatedAt.UTC()
// Every work item type group except the one in the "iteration" bucket are
// meant to be shown in the sidebar.
showInSidebar := (tg.Bucket != workitem.BucketIteration)
res := &app.WorkItemTypeGroupData{
ID: &tg.ID,
Type: APIWorkItemTypeGroups,
Links: &app.GenericLinks{
Related: &workItemTypeGroupRelatedURL,
},
Attributes: &app.WorkItemTypeGroupAttributes{
Bucket: tg.Bucket.String(),
Name: tg.Name,
Description: tg.Description,
Icon: tg.Icon,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
ShowInSidebar: &showInSidebar,
},
Relationships: &app.WorkItemTypeGroupRelationships{
TypeList: &app.RelationGenericList{
Data: make([]*app.GenericData, len(tg.TypeList)),
},
SpaceTemplate: &app.RelationGeneric{
Data: &app.GenericData{
ID: ptr.String(tg.SpaceTemplateID.String()),
Type: &APISpaceTemplates,
},
},
},
}
for i, witID := range tg.TypeList {
// witRelatedURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(space.SystemSpace, witID))
idStr := witID.String()
res.Relationships.TypeList.Data[i] = &app.GenericData{
ID: &idStr,
Type: &workitemtypes,
// Links: &app.GenericLinks{
// Related: &witRelatedURL,
// },
}
}
return res
} | [
"func",
"ConvertTypeGroup",
"(",
"request",
"*",
"http",
".",
"Request",
",",
"tg",
"workitem",
".",
"WorkItemTypeGroup",
")",
"*",
"app",
".",
"WorkItemTypeGroupData",
"{",
"workitemtypes",
":=",
"\"",
"\"",
"\n",
"workItemTypeGroupRelatedURL",
":=",
"rest",
".",
"AbsoluteURL",
"(",
"request",
",",
"app",
".",
"WorkItemTypeGroupHref",
"(",
"tg",
".",
"ID",
")",
")",
"\n",
"createdAt",
":=",
"tg",
".",
"CreatedAt",
".",
"UTC",
"(",
")",
"\n",
"updatedAt",
":=",
"tg",
".",
"UpdatedAt",
".",
"UTC",
"(",
")",
"\n",
"// Every work item type group except the one in the \"iteration\" bucket are",
"// meant to be shown in the sidebar.",
"showInSidebar",
":=",
"(",
"tg",
".",
"Bucket",
"!=",
"workitem",
".",
"BucketIteration",
")",
"\n\n",
"res",
":=",
"&",
"app",
".",
"WorkItemTypeGroupData",
"{",
"ID",
":",
"&",
"tg",
".",
"ID",
",",
"Type",
":",
"APIWorkItemTypeGroups",
",",
"Links",
":",
"&",
"app",
".",
"GenericLinks",
"{",
"Related",
":",
"&",
"workItemTypeGroupRelatedURL",
",",
"}",
",",
"Attributes",
":",
"&",
"app",
".",
"WorkItemTypeGroupAttributes",
"{",
"Bucket",
":",
"tg",
".",
"Bucket",
".",
"String",
"(",
")",
",",
"Name",
":",
"tg",
".",
"Name",
",",
"Description",
":",
"tg",
".",
"Description",
",",
"Icon",
":",
"tg",
".",
"Icon",
",",
"CreatedAt",
":",
"&",
"createdAt",
",",
"UpdatedAt",
":",
"&",
"updatedAt",
",",
"ShowInSidebar",
":",
"&",
"showInSidebar",
",",
"}",
",",
"Relationships",
":",
"&",
"app",
".",
"WorkItemTypeGroupRelationships",
"{",
"TypeList",
":",
"&",
"app",
".",
"RelationGenericList",
"{",
"Data",
":",
"make",
"(",
"[",
"]",
"*",
"app",
".",
"GenericData",
",",
"len",
"(",
"tg",
".",
"TypeList",
")",
")",
",",
"}",
",",
"SpaceTemplate",
":",
"&",
"app",
".",
"RelationGeneric",
"{",
"Data",
":",
"&",
"app",
".",
"GenericData",
"{",
"ID",
":",
"ptr",
".",
"String",
"(",
"tg",
".",
"SpaceTemplateID",
".",
"String",
"(",
")",
")",
",",
"Type",
":",
"&",
"APISpaceTemplates",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"for",
"i",
",",
"witID",
":=",
"range",
"tg",
".",
"TypeList",
"{",
"// witRelatedURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(space.SystemSpace, witID))",
"idStr",
":=",
"witID",
".",
"String",
"(",
")",
"\n",
"res",
".",
"Relationships",
".",
"TypeList",
".",
"Data",
"[",
"i",
"]",
"=",
"&",
"app",
".",
"GenericData",
"{",
"ID",
":",
"&",
"idStr",
",",
"Type",
":",
"&",
"workitemtypes",
",",
"// Links: &app.GenericLinks{",
"// Related: &witRelatedURL,",
"// },",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // ConvertTypeGroup converts WorkitemTypeGroup model to a response resource
// object for jsonapi.org specification | [
"ConvertTypeGroup",
"converts",
"WorkitemTypeGroup",
"model",
"to",
"a",
"response",
"resource",
"object",
"for",
"jsonapi",
".",
"org",
"specification"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/work_item_type_group.go#L55-L104 |
13,461 | fabric8-services/fabric8-wit | gormapplication/application.go | Commit | func (g *GormTransaction) Commit() error {
err := g.db.Commit().Error
g.db = nil
return errors.WithStack(err)
} | go | func (g *GormTransaction) Commit() error {
err := g.db.Commit().Error
g.db = nil
return errors.WithStack(err)
} | [
"func",
"(",
"g",
"*",
"GormTransaction",
")",
"Commit",
"(",
")",
"error",
"{",
"err",
":=",
"g",
".",
"db",
".",
"Commit",
"(",
")",
".",
"Error",
"\n",
"g",
".",
"db",
"=",
"nil",
"\n",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}"
] | // Commit implements TransactionSupport | [
"Commit",
"implements",
"TransactionSupport"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/gormapplication/application.go#L204-L208 |
13,462 | fabric8-services/fabric8-wit | codebase/che/client.go | NewStarterClient | func NewStarterClient(cheStarterURL, openshiftMasterURL string, namespace string, client *http.Client) Client {
return &StarterClient{cheStarterURL: cheStarterURL, openshiftMasterURL: openshiftMasterURL, namespace: namespace, client: client}
} | go | func NewStarterClient(cheStarterURL, openshiftMasterURL string, namespace string, client *http.Client) Client {
return &StarterClient{cheStarterURL: cheStarterURL, openshiftMasterURL: openshiftMasterURL, namespace: namespace, client: client}
} | [
"func",
"NewStarterClient",
"(",
"cheStarterURL",
",",
"openshiftMasterURL",
"string",
",",
"namespace",
"string",
",",
"client",
"*",
"http",
".",
"Client",
")",
"Client",
"{",
"return",
"&",
"StarterClient",
"{",
"cheStarterURL",
":",
"cheStarterURL",
",",
"openshiftMasterURL",
":",
"openshiftMasterURL",
",",
"namespace",
":",
"namespace",
",",
"client",
":",
"client",
"}",
"\n",
"}"
] | // NewStarterClient is a helper function to create a new CheStarter client
// Uses http.DefaultClient | [
"NewStarterClient",
"is",
"a",
"helper",
"function",
"to",
"create",
"a",
"new",
"CheStarter",
"client",
"Uses",
"http",
".",
"DefaultClient"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/codebase/che/client.go#L29-L31 |
13,463 | fabric8-services/fabric8-wit | codebase/che/client.go | CreateWorkspace | func (cs *StarterClient) CreateWorkspace(ctx context.Context, workspace WorkspaceRequest) (*WorkspaceResponse, error) {
body, err := json.Marshal(&workspace)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to create request object")
return nil, err
}
req, err := http.NewRequest("POST", cs.targetURL("workspace"), bytes.NewReader(body))
if err != nil {
return nil, err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "request object")
}
resp, err := cs.client.Do(req)
if err != nil {
return nil, err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
workspaceErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to decode error response from create workspace for repository")
return nil, err
}
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": workspaceErr.String(),
}, "failed to execute create workspace for repository")
return nil, &workspaceErr
}
workspaceResp := WorkspaceResponse{}
err = json.NewDecoder(resp.Body).Decode(&workspaceResp)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to decode response from create workspace for repository")
return nil, err
}
return &workspaceResp, nil
} | go | func (cs *StarterClient) CreateWorkspace(ctx context.Context, workspace WorkspaceRequest) (*WorkspaceResponse, error) {
body, err := json.Marshal(&workspace)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to create request object")
return nil, err
}
req, err := http.NewRequest("POST", cs.targetURL("workspace"), bytes.NewReader(body))
if err != nil {
return nil, err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "request object")
}
resp, err := cs.client.Do(req)
if err != nil {
return nil, err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
workspaceErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to decode error response from create workspace for repository")
return nil, err
}
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": workspaceErr.String(),
}, "failed to execute create workspace for repository")
return nil, &workspaceErr
}
workspaceResp := WorkspaceResponse{}
err = json.NewDecoder(resp.Body).Decode(&workspaceResp)
if err != nil {
log.Error(ctx, map[string]interface{}{
"workspace_id": workspace.Name,
"workspace_stack_id": workspace.StackID,
"workspace": workspace,
"err": err,
}, "failed to decode response from create workspace for repository")
return nil, err
}
return &workspaceResp, nil
} | [
"func",
"(",
"cs",
"*",
"StarterClient",
")",
"CreateWorkspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"workspace",
"WorkspaceRequest",
")",
"(",
"*",
"WorkspaceResponse",
",",
"error",
")",
"{",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"&",
"workspace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspace",
".",
"Name",
",",
"\"",
"\"",
":",
"workspace",
".",
"StackID",
",",
"\"",
"\"",
":",
"workspace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"cs",
".",
"targetURL",
"(",
"\"",
"\"",
")",
",",
"bytes",
".",
"NewReader",
"(",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cs",
".",
"setHeaders",
"(",
"ctx",
",",
"req",
")",
"\n\n",
"if",
"log",
".",
"IsDebug",
"(",
")",
"{",
"b",
",",
"_",
":=",
"httputil",
".",
"DumpRequest",
"(",
"req",
",",
"true",
")",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"string",
"(",
"b",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"cs",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"rest",
".",
"CloseResponse",
"(",
"resp",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusCreated",
"&&",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"workspaceErr",
":=",
"StarterError",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"workspaceErr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspace",
".",
"Name",
",",
"\"",
"\"",
":",
"workspace",
".",
"StackID",
",",
"\"",
"\"",
":",
"workspace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspace",
".",
"Name",
",",
"\"",
"\"",
":",
"workspace",
".",
"StackID",
",",
"\"",
"\"",
":",
"workspace",
",",
"\"",
"\"",
":",
"workspaceErr",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"&",
"workspaceErr",
"\n",
"}",
"\n\n",
"workspaceResp",
":=",
"WorkspaceResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"workspaceResp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspace",
".",
"Name",
",",
"\"",
"\"",
":",
"workspace",
".",
"StackID",
",",
"\"",
"\"",
":",
"workspace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"workspaceResp",
",",
"nil",
"\n",
"}"
] | // CreateWorkspace creates a new Che Workspace based on a repository | [
"CreateWorkspace",
"creates",
"a",
"new",
"Che",
"Workspace",
"based",
"on",
"a",
"repository"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/codebase/che/client.go#L112-L177 |
13,464 | fabric8-services/fabric8-wit | codebase/che/client.go | DeleteWorkspace | func (cs *StarterClient) DeleteWorkspace(ctx context.Context, workspaceName string) error {
req, err := http.NewRequest("DELETE", cs.targetURL(fmt.Sprintf("workspace/%s", workspaceName)), nil)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to create request object")
return err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "request object")
}
resp, err := cs.client.Do(req)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to delete workspace")
return err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK {
workspaceErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to decode error response from list workspace for repository")
return err
}
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": workspaceErr.String(),
}, "failed to delete workspace")
return &workspaceErr
}
return nil
} | go | func (cs *StarterClient) DeleteWorkspace(ctx context.Context, workspaceName string) error {
req, err := http.NewRequest("DELETE", cs.targetURL(fmt.Sprintf("workspace/%s", workspaceName)), nil)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to create request object")
return err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "request object")
}
resp, err := cs.client.Do(req)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to delete workspace")
return err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusNoContent && resp.StatusCode != http.StatusOK {
workspaceErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&workspaceErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": err,
}, "failed to decode error response from list workspace for repository")
return err
}
log.Error(ctx, map[string]interface{}{
"name": workspaceName,
"masterURL": cs.cheStarterURL,
"namespace": cs.namespace,
"err": workspaceErr.String(),
}, "failed to delete workspace")
return &workspaceErr
}
return nil
} | [
"func",
"(",
"cs",
"*",
"StarterClient",
")",
"DeleteWorkspace",
"(",
"ctx",
"context",
".",
"Context",
",",
"workspaceName",
"string",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"cs",
".",
"targetURL",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"workspaceName",
")",
")",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspaceName",
",",
"\"",
"\"",
":",
"cs",
".",
"cheStarterURL",
",",
"\"",
"\"",
":",
"cs",
".",
"namespace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"cs",
".",
"setHeaders",
"(",
"ctx",
",",
"req",
")",
"\n\n",
"if",
"log",
".",
"IsDebug",
"(",
")",
"{",
"b",
",",
"_",
":=",
"httputil",
".",
"DumpRequest",
"(",
"req",
",",
"true",
")",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"string",
"(",
"b",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"cs",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspaceName",
",",
"\"",
"\"",
":",
"cs",
".",
"cheStarterURL",
",",
"\"",
"\"",
":",
"cs",
".",
"namespace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"rest",
".",
"CloseResponse",
"(",
"resp",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusNoContent",
"&&",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"workspaceErr",
":=",
"StarterError",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"workspaceErr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspaceName",
",",
"\"",
"\"",
":",
"cs",
".",
"cheStarterURL",
",",
"\"",
"\"",
":",
"cs",
".",
"namespace",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"workspaceName",
",",
"\"",
"\"",
":",
"cs",
".",
"cheStarterURL",
",",
"\"",
"\"",
":",
"cs",
".",
"namespace",
",",
"\"",
"\"",
":",
"workspaceErr",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"workspaceErr",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // DeleteWorkspace deletes a Che Workspace by its name | [
"DeleteWorkspace",
"deletes",
"a",
"Che",
"Workspace",
"by",
"its",
"name"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/codebase/che/client.go#L180-L235 |
13,465 | fabric8-services/fabric8-wit | codebase/che/client.go | GetCheServerState | func (cs *StarterClient) GetCheServerState(ctx context.Context) (*ServerStateResponse, error) {
req, err := http.NewRequest("GET", cs.targetURL("server"), nil)
if err != nil {
return nil, err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "dump of the request to get the che server state")
}
resp, err := cs.client.Do(req)
if err != nil {
return nil, err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
statusErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&statusErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to decode error response from get che server state")
return nil, err
}
log.Error(ctx, map[string]interface{}{
"err": statusErr.String(),
}, "failed to execute get che server state")
return nil, &statusErr
}
cheServerStateResponse := ServerStateResponse{}
err = json.NewDecoder(resp.Body).Decode(&cheServerStateResponse)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to decode response from getting che server state")
return nil, err
}
return &cheServerStateResponse, nil
} | go | func (cs *StarterClient) GetCheServerState(ctx context.Context) (*ServerStateResponse, error) {
req, err := http.NewRequest("GET", cs.targetURL("server"), nil)
if err != nil {
return nil, err
}
cs.setHeaders(ctx, req)
if log.IsDebug() {
b, _ := httputil.DumpRequest(req, true)
log.Debug(ctx, map[string]interface{}{
"request": string(b),
}, "dump of the request to get the che server state")
}
resp, err := cs.client.Do(req)
if err != nil {
return nil, err
}
defer rest.CloseResponse(resp)
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
statusErr := StarterError{}
err = json.NewDecoder(resp.Body).Decode(&statusErr)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to decode error response from get che server state")
return nil, err
}
log.Error(ctx, map[string]interface{}{
"err": statusErr.String(),
}, "failed to execute get che server state")
return nil, &statusErr
}
cheServerStateResponse := ServerStateResponse{}
err = json.NewDecoder(resp.Body).Decode(&cheServerStateResponse)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to decode response from getting che server state")
return nil, err
}
return &cheServerStateResponse, nil
} | [
"func",
"(",
"cs",
"*",
"StarterClient",
")",
"GetCheServerState",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"ServerStateResponse",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"cs",
".",
"targetURL",
"(",
"\"",
"\"",
")",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cs",
".",
"setHeaders",
"(",
"ctx",
",",
"req",
")",
"\n\n",
"if",
"log",
".",
"IsDebug",
"(",
")",
"{",
"b",
",",
"_",
":=",
"httputil",
".",
"DumpRequest",
"(",
"req",
",",
"true",
")",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"string",
"(",
"b",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"cs",
".",
"client",
".",
"Do",
"(",
"req",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defer",
"rest",
".",
"CloseResponse",
"(",
"resp",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusCreated",
"&&",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"statusErr",
":=",
"StarterError",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"statusErr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"statusErr",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"&",
"statusErr",
"\n",
"}",
"\n\n",
"cheServerStateResponse",
":=",
"ServerStateResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"cheServerStateResponse",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"cheServerStateResponse",
",",
"nil",
"\n",
"}"
] | // GetCheServerState get che server state. | [
"GetCheServerState",
"get",
"che",
"server",
"state",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/codebase/che/client.go#L293-L341 |
13,466 | fabric8-services/fabric8-wit | remoteworkitem/jira.go | Fetch | func (j *JiraTracker) Fetch(authToken string) chan TrackerItemContent {
f := jiraIssueFetcher{}
client, _ := jira.NewClient(nil, j.URL)
f.client = client
return j.fetch(&f)
} | go | func (j *JiraTracker) Fetch(authToken string) chan TrackerItemContent {
f := jiraIssueFetcher{}
client, _ := jira.NewClient(nil, j.URL)
f.client = client
return j.fetch(&f)
} | [
"func",
"(",
"j",
"*",
"JiraTracker",
")",
"Fetch",
"(",
"authToken",
"string",
")",
"chan",
"TrackerItemContent",
"{",
"f",
":=",
"jiraIssueFetcher",
"{",
"}",
"\n",
"client",
",",
"_",
":=",
"jira",
".",
"NewClient",
"(",
"nil",
",",
"j",
".",
"URL",
")",
"\n",
"f",
".",
"client",
"=",
"client",
"\n",
"return",
"j",
".",
"fetch",
"(",
"&",
"f",
")",
"\n",
"}"
] | // Fetch collects data from Jira | [
"Fetch",
"collects",
"data",
"from",
"Jira"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/remoteworkitem/jira.go#L33-L38 |
13,467 | fabric8-services/fabric8-wit | workitem/link/ancestor.go | GetDistinctAncestorIDs | func (l AncestorList) GetDistinctAncestorIDs() id.Slice {
m := id.Map{}
for _, ancestor := range l {
m[ancestor.ID] = struct{}{}
}
return m.ToSlice()
} | go | func (l AncestorList) GetDistinctAncestorIDs() id.Slice {
m := id.Map{}
for _, ancestor := range l {
m[ancestor.ID] = struct{}{}
}
return m.ToSlice()
} | [
"func",
"(",
"l",
"AncestorList",
")",
"GetDistinctAncestorIDs",
"(",
")",
"id",
".",
"Slice",
"{",
"m",
":=",
"id",
".",
"Map",
"{",
"}",
"\n",
"for",
"_",
",",
"ancestor",
":=",
"range",
"l",
"{",
"m",
"[",
"ancestor",
".",
"ID",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"m",
".",
"ToSlice",
"(",
")",
"\n",
"}"
] | // GetDistinctAncestorIDs returns a list with distinct ancestor IDs. | [
"GetDistinctAncestorIDs",
"returns",
"a",
"list",
"with",
"distinct",
"ancestor",
"IDs",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/link/ancestor.go#L35-L41 |
13,468 | fabric8-services/fabric8-wit | workitem/link/ancestor.go | GetParentOf | func (l AncestorList) GetParentOf(workItemID uuid.UUID) *Ancestor {
for _, a := range l {
if a.DirectChildID == workItemID {
return &a
}
}
return nil
} | go | func (l AncestorList) GetParentOf(workItemID uuid.UUID) *Ancestor {
for _, a := range l {
if a.DirectChildID == workItemID {
return &a
}
}
return nil
} | [
"func",
"(",
"l",
"AncestorList",
")",
"GetParentOf",
"(",
"workItemID",
"uuid",
".",
"UUID",
")",
"*",
"Ancestor",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"l",
"{",
"if",
"a",
".",
"DirectChildID",
"==",
"workItemID",
"{",
"return",
"&",
"a",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GetParentOf returns the first parent item that we can find in the list of
// ancestors; otherwise nil is returned. | [
"GetParentOf",
"returns",
"the",
"first",
"parent",
"item",
"that",
"we",
"can",
"find",
"in",
"the",
"list",
"of",
"ancestors",
";",
"otherwise",
"nil",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/link/ancestor.go#L45-L52 |
13,469 | fabric8-services/fabric8-wit | workitem/typegroup.go | Equal | func (witg WorkItemTypeGroup) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemTypeGroup)
if !ok {
return false
}
if witg.ID != other.ID {
return false
}
if witg.SpaceTemplateID != other.SpaceTemplateID {
return false
}
if !convert.CascadeEqual(witg.Lifecycle, other.Lifecycle) {
return false
}
if witg.Name != other.Name {
return false
}
if !reflect.DeepEqual(witg.Description, other.Description) {
return false
}
if witg.Bucket != other.Bucket {
return false
}
if witg.Icon != other.Icon {
return false
}
if witg.Position != other.Position {
return false
}
if len(witg.TypeList) != len(other.TypeList) {
return false
}
for i := range witg.TypeList {
if witg.TypeList[i] != other.TypeList[i] {
return false
}
}
return true
} | go | func (witg WorkItemTypeGroup) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemTypeGroup)
if !ok {
return false
}
if witg.ID != other.ID {
return false
}
if witg.SpaceTemplateID != other.SpaceTemplateID {
return false
}
if !convert.CascadeEqual(witg.Lifecycle, other.Lifecycle) {
return false
}
if witg.Name != other.Name {
return false
}
if !reflect.DeepEqual(witg.Description, other.Description) {
return false
}
if witg.Bucket != other.Bucket {
return false
}
if witg.Icon != other.Icon {
return false
}
if witg.Position != other.Position {
return false
}
if len(witg.TypeList) != len(other.TypeList) {
return false
}
for i := range witg.TypeList {
if witg.TypeList[i] != other.TypeList[i] {
return false
}
}
return true
} | [
"func",
"(",
"witg",
"WorkItemTypeGroup",
")",
"Equal",
"(",
"u",
"convert",
".",
"Equaler",
")",
"bool",
"{",
"other",
",",
"ok",
":=",
"u",
".",
"(",
"WorkItemTypeGroup",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"ID",
"!=",
"other",
".",
"ID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"SpaceTemplateID",
"!=",
"other",
".",
"SpaceTemplateID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"convert",
".",
"CascadeEqual",
"(",
"witg",
".",
"Lifecycle",
",",
"other",
".",
"Lifecycle",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"Name",
"!=",
"other",
".",
"Name",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"witg",
".",
"Description",
",",
"other",
".",
"Description",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"Bucket",
"!=",
"other",
".",
"Bucket",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"Icon",
"!=",
"other",
".",
"Icon",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"witg",
".",
"Position",
"!=",
"other",
".",
"Position",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"witg",
".",
"TypeList",
")",
"!=",
"len",
"(",
"other",
".",
"TypeList",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"witg",
".",
"TypeList",
"{",
"if",
"witg",
".",
"TypeList",
"[",
"i",
"]",
"!=",
"other",
".",
"TypeList",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Equal returns true if two WorkItemTypeGroup objects are equal; otherwise false is returned. | [
"Equal",
"returns",
"true",
"if",
"two",
"WorkItemTypeGroup",
"objects",
"are",
"equal",
";",
"otherwise",
"false",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/typegroup.go#L59-L97 |
13,470 | fabric8-services/fabric8-wit | workitem/typegroup.go | TypeGroups | func TypeGroups() []WorkItemTypeGroup {
scenariosID := uuid.FromStringOrNil("feb28a28-44a6-43f8-946a-bae987713891")
experiencesID := uuid.FromStringOrNil("d4e2c859-f416-4e9a-a3e0-e7bb4e1b454b")
requirementsID := uuid.FromStringOrNil("bb1de8b6-3175-4821-abe9-50d0a64f19a2")
executionID := uuid.FromStringOrNil("7fdfde54-9cf2-4098-b33b-30cd505dcfc3")
return []WorkItemTypeGroup{
// There can be more than one groups in the "Portfolio" bucket
{
ID: scenariosID,
Bucket: BucketPortfolio,
Name: "Scenarios",
Icon: "fa fa-bullseye",
TypeList: []uuid.UUID{
SystemScenario,
SystemFundamental,
SystemPapercuts,
},
},
{
ID: experiencesID,
Bucket: BucketPortfolio,
Name: "Experiences",
Icon: "pficon pficon-infrastructure",
TypeList: []uuid.UUID{
SystemExperience,
SystemValueProposition,
},
},
// There's always only one group in the "Requirement" bucket
{
ID: requirementsID,
Bucket: BucketRequirement,
Name: "Requirements",
Icon: "fa fa-list-ul",
TypeList: []uuid.UUID{
SystemFeature,
SystemBug,
},
},
// There's always only one group in the "Iteration" bucket
{
ID: executionID,
Bucket: BucketIteration,
Name: "Execution",
Icon: "fa fa-repeat",
TypeList: []uuid.UUID{
SystemTask,
SystemBug,
SystemFeature,
},
},
}
} | go | func TypeGroups() []WorkItemTypeGroup {
scenariosID := uuid.FromStringOrNil("feb28a28-44a6-43f8-946a-bae987713891")
experiencesID := uuid.FromStringOrNil("d4e2c859-f416-4e9a-a3e0-e7bb4e1b454b")
requirementsID := uuid.FromStringOrNil("bb1de8b6-3175-4821-abe9-50d0a64f19a2")
executionID := uuid.FromStringOrNil("7fdfde54-9cf2-4098-b33b-30cd505dcfc3")
return []WorkItemTypeGroup{
// There can be more than one groups in the "Portfolio" bucket
{
ID: scenariosID,
Bucket: BucketPortfolio,
Name: "Scenarios",
Icon: "fa fa-bullseye",
TypeList: []uuid.UUID{
SystemScenario,
SystemFundamental,
SystemPapercuts,
},
},
{
ID: experiencesID,
Bucket: BucketPortfolio,
Name: "Experiences",
Icon: "pficon pficon-infrastructure",
TypeList: []uuid.UUID{
SystemExperience,
SystemValueProposition,
},
},
// There's always only one group in the "Requirement" bucket
{
ID: requirementsID,
Bucket: BucketRequirement,
Name: "Requirements",
Icon: "fa fa-list-ul",
TypeList: []uuid.UUID{
SystemFeature,
SystemBug,
},
},
// There's always only one group in the "Iteration" bucket
{
ID: executionID,
Bucket: BucketIteration,
Name: "Execution",
Icon: "fa fa-repeat",
TypeList: []uuid.UUID{
SystemTask,
SystemBug,
SystemFeature,
},
},
}
} | [
"func",
"TypeGroups",
"(",
")",
"[",
"]",
"WorkItemTypeGroup",
"{",
"scenariosID",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"\"",
"\"",
")",
"\n",
"experiencesID",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"\"",
"\"",
")",
"\n",
"requirementsID",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"\"",
"\"",
")",
"\n",
"executionID",
":=",
"uuid",
".",
"FromStringOrNil",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"[",
"]",
"WorkItemTypeGroup",
"{",
"// There can be more than one groups in the \"Portfolio\" bucket",
"{",
"ID",
":",
"scenariosID",
",",
"Bucket",
":",
"BucketPortfolio",
",",
"Name",
":",
"\"",
"\"",
",",
"Icon",
":",
"\"",
"\"",
",",
"TypeList",
":",
"[",
"]",
"uuid",
".",
"UUID",
"{",
"SystemScenario",
",",
"SystemFundamental",
",",
"SystemPapercuts",
",",
"}",
",",
"}",
",",
"{",
"ID",
":",
"experiencesID",
",",
"Bucket",
":",
"BucketPortfolio",
",",
"Name",
":",
"\"",
"\"",
",",
"Icon",
":",
"\"",
"\"",
",",
"TypeList",
":",
"[",
"]",
"uuid",
".",
"UUID",
"{",
"SystemExperience",
",",
"SystemValueProposition",
",",
"}",
",",
"}",
",",
"// There's always only one group in the \"Requirement\" bucket",
"{",
"ID",
":",
"requirementsID",
",",
"Bucket",
":",
"BucketRequirement",
",",
"Name",
":",
"\"",
"\"",
",",
"Icon",
":",
"\"",
"\"",
",",
"TypeList",
":",
"[",
"]",
"uuid",
".",
"UUID",
"{",
"SystemFeature",
",",
"SystemBug",
",",
"}",
",",
"}",
",",
"// There's always only one group in the \"Iteration\" bucket",
"{",
"ID",
":",
"executionID",
",",
"Bucket",
":",
"BucketIteration",
",",
"Name",
":",
"\"",
"\"",
",",
"Icon",
":",
"\"",
"\"",
",",
"TypeList",
":",
"[",
"]",
"uuid",
".",
"UUID",
"{",
"SystemTask",
",",
"SystemBug",
",",
"SystemFeature",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] | // TypeGroups returns the list of work item type groups | [
"TypeGroups",
"returns",
"the",
"list",
"of",
"work",
"item",
"type",
"groups"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/typegroup.go#L133-L186 |
13,471 | fabric8-services/fabric8-wit | workitem/typegroup.go | TypeGroupByName | func TypeGroupByName(name string) *WorkItemTypeGroup {
for _, t := range TypeGroups() {
if t.Name == name {
return &t
}
}
return nil
} | go | func TypeGroupByName(name string) *WorkItemTypeGroup {
for _, t := range TypeGroups() {
if t.Name == name {
return &t
}
}
return nil
} | [
"func",
"TypeGroupByName",
"(",
"name",
"string",
")",
"*",
"WorkItemTypeGroup",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"TypeGroups",
"(",
")",
"{",
"if",
"t",
".",
"Name",
"==",
"name",
"{",
"return",
"&",
"t",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // TypeGroupByName returns a type group based on its name if such a group
// exists; otherwise nil is returned. | [
"TypeGroupByName",
"returns",
"a",
"type",
"group",
"based",
"on",
"its",
"name",
"if",
"such",
"a",
"group",
"exists",
";",
"otherwise",
"nil",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/typegroup.go#L190-L197 |
13,472 | fabric8-services/fabric8-wit | workitem/typegroup.go | TypeGroupsByBucket | func TypeGroupsByBucket(bucket TypeBucket) []WorkItemTypeGroup {
res := []WorkItemTypeGroup{}
for _, t := range TypeGroups() {
if t.Bucket == bucket {
res = append(res, t)
}
}
return res
} | go | func TypeGroupsByBucket(bucket TypeBucket) []WorkItemTypeGroup {
res := []WorkItemTypeGroup{}
for _, t := range TypeGroups() {
if t.Bucket == bucket {
res = append(res, t)
}
}
return res
} | [
"func",
"TypeGroupsByBucket",
"(",
"bucket",
"TypeBucket",
")",
"[",
"]",
"WorkItemTypeGroup",
"{",
"res",
":=",
"[",
"]",
"WorkItemTypeGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"t",
":=",
"range",
"TypeGroups",
"(",
")",
"{",
"if",
"t",
".",
"Bucket",
"==",
"bucket",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // TypeGroupsByBucket returns all type groups which fall into the given bucket | [
"TypeGroupsByBucket",
"returns",
"all",
"type",
"groups",
"which",
"fall",
"into",
"the",
"given",
"bucket"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/typegroup.go#L200-L208 |
13,473 | fabric8-services/fabric8-wit | controller/workitemtypes.go | NewWorkitemtypesController | func NewWorkitemtypesController(service *goa.Service, db application.DB, config workItemTypesControllerConfiguration) *WorkitemtypesController {
return &WorkitemtypesController{
Controller: service.NewController("WorkitemtypesController"),
db: db,
config: config,
}
} | go | func NewWorkitemtypesController(service *goa.Service, db application.DB, config workItemTypesControllerConfiguration) *WorkitemtypesController {
return &WorkitemtypesController{
Controller: service.NewController("WorkitemtypesController"),
db: db,
config: config,
}
} | [
"func",
"NewWorkitemtypesController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
",",
"config",
"workItemTypesControllerConfiguration",
")",
"*",
"WorkitemtypesController",
"{",
"return",
"&",
"WorkitemtypesController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
",",
"config",
":",
"config",
",",
"}",
"\n",
"}"
] | // NewWorkitemtypesController creates a workitemtype controller. | [
"NewWorkitemtypesController",
"creates",
"a",
"workitemtype",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitemtypes.go#L25-L31 |
13,474 | fabric8-services/fabric8-wit | controller/workitemtypes.go | List | func (c *WorkitemtypesController) List(ctx *app.ListWorkitemtypesContext) error {
log.Debug(ctx, map[string]interface{}{"space_id": ctx.SpaceTemplateID}, "Listing work item types per space template")
result := &app.WorkItemTypeList{}
err := application.Transactional(c.db, func(appl application.Application) error {
witModels, err := appl.WorkItemTypes().List(ctx.Context, ctx.SpaceTemplateID)
if err != nil {
return errs.Wrap(err, "Error listing work item types")
}
return ctx.ConditionalEntities(witModels, c.config.GetCacheControlWorkItemTypes, func() error {
// convert from model to app
// result := &app.WorkItemTypeList{}
result.Data = make([]*app.WorkItemTypeData, len(witModels))
for index, value := range witModels {
wit := ConvertWorkItemTypeFromModel(ctx.Request, &value)
result.Data[index] = &wit
}
return nil
})
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(result)
} | go | func (c *WorkitemtypesController) List(ctx *app.ListWorkitemtypesContext) error {
log.Debug(ctx, map[string]interface{}{"space_id": ctx.SpaceTemplateID}, "Listing work item types per space template")
result := &app.WorkItemTypeList{}
err := application.Transactional(c.db, func(appl application.Application) error {
witModels, err := appl.WorkItemTypes().List(ctx.Context, ctx.SpaceTemplateID)
if err != nil {
return errs.Wrap(err, "Error listing work item types")
}
return ctx.ConditionalEntities(witModels, c.config.GetCacheControlWorkItemTypes, func() error {
// convert from model to app
// result := &app.WorkItemTypeList{}
result.Data = make([]*app.WorkItemTypeData, len(witModels))
for index, value := range witModels {
wit := ConvertWorkItemTypeFromModel(ctx.Request, &value)
result.Data[index] = &wit
}
return nil
})
})
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(result)
} | [
"func",
"(",
"c",
"*",
"WorkitemtypesController",
")",
"List",
"(",
"ctx",
"*",
"app",
".",
"ListWorkitemtypesContext",
")",
"error",
"{",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ctx",
".",
"SpaceTemplateID",
"}",
",",
"\"",
"\"",
")",
"\n",
"result",
":=",
"&",
"app",
".",
"WorkItemTypeList",
"{",
"}",
"\n",
"err",
":=",
"application",
".",
"Transactional",
"(",
"c",
".",
"db",
",",
"func",
"(",
"appl",
"application",
".",
"Application",
")",
"error",
"{",
"witModels",
",",
"err",
":=",
"appl",
".",
"WorkItemTypes",
"(",
")",
".",
"List",
"(",
"ctx",
".",
"Context",
",",
"ctx",
".",
"SpaceTemplateID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ctx",
".",
"ConditionalEntities",
"(",
"witModels",
",",
"c",
".",
"config",
".",
"GetCacheControlWorkItemTypes",
",",
"func",
"(",
")",
"error",
"{",
"// convert from model to app",
"// result := &app.WorkItemTypeList{}",
"result",
".",
"Data",
"=",
"make",
"(",
"[",
"]",
"*",
"app",
".",
"WorkItemTypeData",
",",
"len",
"(",
"witModels",
")",
")",
"\n",
"for",
"index",
",",
"value",
":=",
"range",
"witModels",
"{",
"wit",
":=",
"ConvertWorkItemTypeFromModel",
"(",
"ctx",
".",
"Request",
",",
"&",
"value",
")",
"\n",
"result",
".",
"Data",
"[",
"index",
"]",
"=",
"&",
"wit",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"OK",
"(",
"result",
")",
"\n",
"}"
] | // List runs the list action | [
"List",
"runs",
"the",
"list",
"action"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/workitemtypes.go#L34-L58 |
13,475 | fabric8-services/fabric8-wit | controller/space_codebases.go | NewSpaceCodebasesController | func NewSpaceCodebasesController(service *goa.Service, db application.DB) *SpaceCodebasesController {
return &SpaceCodebasesController{Controller: service.NewController("SpaceCodebasesController"), db: db}
} | go | func NewSpaceCodebasesController(service *goa.Service, db application.DB) *SpaceCodebasesController {
return &SpaceCodebasesController{Controller: service.NewController("SpaceCodebasesController"), db: db}
} | [
"func",
"NewSpaceCodebasesController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
")",
"*",
"SpaceCodebasesController",
"{",
"return",
"&",
"SpaceCodebasesController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
"}",
"\n",
"}"
] | // NewSpaceCodebasesController creates a space-codebases controller. | [
"NewSpaceCodebasesController",
"creates",
"a",
"space",
"-",
"codebases",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/space_codebases.go#L22-L24 |
13,476 | fabric8-services/fabric8-wit | criteria/expression_equals.go | Equals | func Equals(left Expression, right Expression) Expression {
return reparent(&EqualsExpression{binaryExpression{expression{}, left, right}})
} | go | func Equals(left Expression, right Expression) Expression {
return reparent(&EqualsExpression{binaryExpression{expression{}, left, right}})
} | [
"func",
"Equals",
"(",
"left",
"Expression",
",",
"right",
"Expression",
")",
"Expression",
"{",
"return",
"reparent",
"(",
"&",
"EqualsExpression",
"{",
"binaryExpression",
"{",
"expression",
"{",
"}",
",",
"left",
",",
"right",
"}",
"}",
")",
"\n",
"}"
] | // Equals constructs an EqualsExpression | [
"Equals",
"constructs",
"an",
"EqualsExpression"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/criteria/expression_equals.go#L18-L20 |
13,477 | fabric8-services/fabric8-wit | log/context.go | extractIdentityID | func extractIdentityID(ctx context.Context) (string, error) {
token := goajwt.ContextJWT(ctx)
if token == nil {
return "", errors.New("Missing token")
}
id := token.Claims.(jwt.MapClaims)["sub"]
if id == nil {
return "", errors.New("Missing sub")
}
return id.(string), nil
} | go | func extractIdentityID(ctx context.Context) (string, error) {
token := goajwt.ContextJWT(ctx)
if token == nil {
return "", errors.New("Missing token")
}
id := token.Claims.(jwt.MapClaims)["sub"]
if id == nil {
return "", errors.New("Missing sub")
}
return id.(string), nil
} | [
"func",
"extractIdentityID",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"token",
":=",
"goajwt",
".",
"ContextJWT",
"(",
"ctx",
")",
"\n",
"if",
"token",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"id",
":=",
"token",
".",
"Claims",
".",
"(",
"jwt",
".",
"MapClaims",
")",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"id",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"id",
".",
"(",
"string",
")",
",",
"nil",
"\n",
"}"
] | // extractIdentityID obtains the identity ID out of the authentication context | [
"extractIdentityID",
"obtains",
"the",
"identity",
"ID",
"out",
"of",
"the",
"authentication",
"context"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/log/context.go#L14-L25 |
13,478 | fabric8-services/fabric8-wit | log/context.go | ExtractRequestID | func ExtractRequestID(ctx context.Context) string {
reqID := middleware.ContextRequestID(ctx)
if reqID == "" {
return client.ContextRequestID(ctx)
}
return reqID
} | go | func ExtractRequestID(ctx context.Context) string {
reqID := middleware.ContextRequestID(ctx)
if reqID == "" {
return client.ContextRequestID(ctx)
}
return reqID
} | [
"func",
"ExtractRequestID",
"(",
"ctx",
"context",
".",
"Context",
")",
"string",
"{",
"reqID",
":=",
"middleware",
".",
"ContextRequestID",
"(",
"ctx",
")",
"\n",
"if",
"reqID",
"==",
"\"",
"\"",
"{",
"return",
"client",
".",
"ContextRequestID",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"return",
"reqID",
"\n",
"}"
] | // ExtractRequestID obtains the request ID either from a goa client or middleware | [
"ExtractRequestID",
"obtains",
"the",
"request",
"ID",
"either",
"from",
"a",
"goa",
"client",
"or",
"middleware"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/log/context.go#L28-L35 |
13,479 | fabric8-services/fabric8-wit | criteria/iterator.go | IteratePostOrder | func IteratePostOrder(exp Expression, visitorFunction func(exp Expression) bool) {
exp.Accept(&postOrderIterator{visitorFunction})
} | go | func IteratePostOrder(exp Expression, visitorFunction func(exp Expression) bool) {
exp.Accept(&postOrderIterator{visitorFunction})
} | [
"func",
"IteratePostOrder",
"(",
"exp",
"Expression",
",",
"visitorFunction",
"func",
"(",
"exp",
"Expression",
")",
"bool",
")",
"{",
"exp",
".",
"Accept",
"(",
"&",
"postOrderIterator",
"{",
"visitorFunction",
"}",
")",
"\n",
"}"
] | // IteratePostOrder walks the expression tree in depth-first, left to right
// order. The iteration stops if visitorFunction returns false. | [
"IteratePostOrder",
"walks",
"the",
"expression",
"tree",
"in",
"depth",
"-",
"first",
"left",
"to",
"right",
"order",
".",
"The",
"iteration",
"stops",
"if",
"visitorFunction",
"returns",
"false",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/criteria/iterator.go#L5-L7 |
13,480 | fabric8-services/fabric8-wit | comment/comment_revision_repository.go | Create | func (r *GormCommentRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, c Comment) error {
log.Debug(nil, map[string]interface{}{
"modifier_id": modifierID,
"revision_type": revisionType,
}, "Storing a revision after operation on comment.")
tx := r.db
revision := &Revision{
ModifierIdentity: modifierID,
Time: time.Now(),
Type: revisionType,
CommentID: c.ID,
CommentParentID: c.ParentID,
CommentBody: &c.Body,
CommentMarkup: &c.Markup,
}
// if there is a valid parent comment id, add it the the stuct
if c.ParentCommentID.Valid == true {
revision.CommentParentCommentID = id.NullUUID{
UUID: c.ParentCommentID.UUID,
Valid: true,
}
}
if revision.Type == RevisionTypeDelete {
revision.CommentBody = nil
revision.CommentMarkup = nil
}
if err := tx.Create(&revision).Error; err != nil {
return errors.NewInternalError(ctx, errs.Wrap(err, "failed to create new comment revision"))
}
log.Debug(ctx, map[string]interface{}{"comment_id": c.ID}, "comment revision occurrence created")
return nil
} | go | func (r *GormCommentRevisionRepository) Create(ctx context.Context, modifierID uuid.UUID, revisionType RevisionType, c Comment) error {
log.Debug(nil, map[string]interface{}{
"modifier_id": modifierID,
"revision_type": revisionType,
}, "Storing a revision after operation on comment.")
tx := r.db
revision := &Revision{
ModifierIdentity: modifierID,
Time: time.Now(),
Type: revisionType,
CommentID: c.ID,
CommentParentID: c.ParentID,
CommentBody: &c.Body,
CommentMarkup: &c.Markup,
}
// if there is a valid parent comment id, add it the the stuct
if c.ParentCommentID.Valid == true {
revision.CommentParentCommentID = id.NullUUID{
UUID: c.ParentCommentID.UUID,
Valid: true,
}
}
if revision.Type == RevisionTypeDelete {
revision.CommentBody = nil
revision.CommentMarkup = nil
}
if err := tx.Create(&revision).Error; err != nil {
return errors.NewInternalError(ctx, errs.Wrap(err, "failed to create new comment revision"))
}
log.Debug(ctx, map[string]interface{}{"comment_id": c.ID}, "comment revision occurrence created")
return nil
} | [
"func",
"(",
"r",
"*",
"GormCommentRevisionRepository",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"modifierID",
"uuid",
".",
"UUID",
",",
"revisionType",
"RevisionType",
",",
"c",
"Comment",
")",
"error",
"{",
"log",
".",
"Debug",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"modifierID",
",",
"\"",
"\"",
":",
"revisionType",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"tx",
":=",
"r",
".",
"db",
"\n",
"revision",
":=",
"&",
"Revision",
"{",
"ModifierIdentity",
":",
"modifierID",
",",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Type",
":",
"revisionType",
",",
"CommentID",
":",
"c",
".",
"ID",
",",
"CommentParentID",
":",
"c",
".",
"ParentID",
",",
"CommentBody",
":",
"&",
"c",
".",
"Body",
",",
"CommentMarkup",
":",
"&",
"c",
".",
"Markup",
",",
"}",
"\n",
"// if there is a valid parent comment id, add it the the stuct",
"if",
"c",
".",
"ParentCommentID",
".",
"Valid",
"==",
"true",
"{",
"revision",
".",
"CommentParentCommentID",
"=",
"id",
".",
"NullUUID",
"{",
"UUID",
":",
"c",
".",
"ParentCommentID",
".",
"UUID",
",",
"Valid",
":",
"true",
",",
"}",
"\n",
"}",
"\n",
"if",
"revision",
".",
"Type",
"==",
"RevisionTypeDelete",
"{",
"revision",
".",
"CommentBody",
"=",
"nil",
"\n",
"revision",
".",
"CommentMarkup",
"=",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Create",
"(",
"&",
"revision",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"c",
".",
"ID",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Create stores a new revision for the given comment. | [
"Create",
"stores",
"a",
"new",
"revision",
"for",
"the",
"given",
"comment",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/comment/comment_revision_repository.go#L37-L69 |
13,481 | fabric8-services/fabric8-wit | controller/planner_backlog.go | NewPlannerBacklogController | func NewPlannerBacklogController(service *goa.Service, db application.DB, config PlannerBacklogControllerConfig) *PlannerBacklogController {
return &PlannerBacklogController{
Controller: service.NewController("PlannerBacklogController"),
db: db,
config: config,
}
} | go | func NewPlannerBacklogController(service *goa.Service, db application.DB, config PlannerBacklogControllerConfig) *PlannerBacklogController {
return &PlannerBacklogController{
Controller: service.NewController("PlannerBacklogController"),
db: db,
config: config,
}
} | [
"func",
"NewPlannerBacklogController",
"(",
"service",
"*",
"goa",
".",
"Service",
",",
"db",
"application",
".",
"DB",
",",
"config",
"PlannerBacklogControllerConfig",
")",
"*",
"PlannerBacklogController",
"{",
"return",
"&",
"PlannerBacklogController",
"{",
"Controller",
":",
"service",
".",
"NewController",
"(",
"\"",
"\"",
")",
",",
"db",
":",
"db",
",",
"config",
":",
"config",
",",
"}",
"\n",
"}"
] | // NewPlannerBacklogController creates a planner_backlog controller. | [
"NewPlannerBacklogController",
"creates",
"a",
"planner_backlog",
"controller",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/planner_backlog.go#L32-L38 |
13,482 | fabric8-services/fabric8-wit | controller/planner_backlog.go | generateBacklogExpression | func generateBacklogExpression(ctx context.Context, db application.DB, spaceID uuid.UUID, exp criteria.Expression) (criteria.Expression, error) {
notClosed := criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed))
if exp != nil {
exp = criteria.And(exp, notClosed)
} else {
exp = notClosed
}
log.Debug(ctx, map[string]interface{}{"space_id": spaceID, "db": db}, "generating backlog expression")
err := application.Transactional(db, func(appl application.Application) error {
// Get the space template ID from the space
space, err := appl.Spaces().Load(ctx, spaceID)
if err != nil {
return errs.Wrapf(err, "unable to fetch space: %s", spaceID)
}
// Get the root iteration
itr, err := appl.Iterations().Root(ctx, spaceID)
if err != nil {
log.Error(ctx, map[string]interface{}{"space_id": spaceID, "err": err}, "failed to locate root iteration")
return errs.Wrap(err, "unable to fetch root iteration")
}
exp = criteria.Equals(criteria.Field(workitem.SystemIteration), criteria.Literal(itr.ID.String()))
// Get the list of work item types that derive of PlannerItem in the space
var expWits criteria.Expression
wits, err := appl.WorkItemTypes().ListPlannerItemTypes(ctx, space.SpaceTemplateID)
if err != nil {
return errs.Wrap(err, "unable to fetch work item types that derive from planner item")
}
if len(wits) >= 1 {
expWits = criteria.Equals(criteria.Field("Type"), criteria.Literal(wits[0].ID.String()))
for _, wit := range wits[1:] {
witIDStr := wit.ID.String()
expWits = criteria.Or(expWits, criteria.Equals(criteria.Field("Type"), criteria.Literal(witIDStr)))
}
exp = criteria.And(exp, expWits)
}
if len(wits) == 0 {
// We set exp to nil to return an empty array
exp = nil
}
return nil
})
if err != nil {
return nil, err
}
return exp, nil
} | go | func generateBacklogExpression(ctx context.Context, db application.DB, spaceID uuid.UUID, exp criteria.Expression) (criteria.Expression, error) {
notClosed := criteria.Not(criteria.Field(workitem.SystemState), criteria.Literal(workitem.SystemStateClosed))
if exp != nil {
exp = criteria.And(exp, notClosed)
} else {
exp = notClosed
}
log.Debug(ctx, map[string]interface{}{"space_id": spaceID, "db": db}, "generating backlog expression")
err := application.Transactional(db, func(appl application.Application) error {
// Get the space template ID from the space
space, err := appl.Spaces().Load(ctx, spaceID)
if err != nil {
return errs.Wrapf(err, "unable to fetch space: %s", spaceID)
}
// Get the root iteration
itr, err := appl.Iterations().Root(ctx, spaceID)
if err != nil {
log.Error(ctx, map[string]interface{}{"space_id": spaceID, "err": err}, "failed to locate root iteration")
return errs.Wrap(err, "unable to fetch root iteration")
}
exp = criteria.Equals(criteria.Field(workitem.SystemIteration), criteria.Literal(itr.ID.String()))
// Get the list of work item types that derive of PlannerItem in the space
var expWits criteria.Expression
wits, err := appl.WorkItemTypes().ListPlannerItemTypes(ctx, space.SpaceTemplateID)
if err != nil {
return errs.Wrap(err, "unable to fetch work item types that derive from planner item")
}
if len(wits) >= 1 {
expWits = criteria.Equals(criteria.Field("Type"), criteria.Literal(wits[0].ID.String()))
for _, wit := range wits[1:] {
witIDStr := wit.ID.String()
expWits = criteria.Or(expWits, criteria.Equals(criteria.Field("Type"), criteria.Literal(witIDStr)))
}
exp = criteria.And(exp, expWits)
}
if len(wits) == 0 {
// We set exp to nil to return an empty array
exp = nil
}
return nil
})
if err != nil {
return nil, err
}
return exp, nil
} | [
"func",
"generateBacklogExpression",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"application",
".",
"DB",
",",
"spaceID",
"uuid",
".",
"UUID",
",",
"exp",
"criteria",
".",
"Expression",
")",
"(",
"criteria",
".",
"Expression",
",",
"error",
")",
"{",
"notClosed",
":=",
"criteria",
".",
"Not",
"(",
"criteria",
".",
"Field",
"(",
"workitem",
".",
"SystemState",
")",
",",
"criteria",
".",
"Literal",
"(",
"workitem",
".",
"SystemStateClosed",
")",
")",
"\n",
"if",
"exp",
"!=",
"nil",
"{",
"exp",
"=",
"criteria",
".",
"And",
"(",
"exp",
",",
"notClosed",
")",
"\n",
"}",
"else",
"{",
"exp",
"=",
"notClosed",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"spaceID",
",",
"\"",
"\"",
":",
"db",
"}",
",",
"\"",
"\"",
")",
"\n",
"err",
":=",
"application",
".",
"Transactional",
"(",
"db",
",",
"func",
"(",
"appl",
"application",
".",
"Application",
")",
"error",
"{",
"// Get the space template ID from the space",
"space",
",",
"err",
":=",
"appl",
".",
"Spaces",
"(",
")",
".",
"Load",
"(",
"ctx",
",",
"spaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"spaceID",
")",
"\n",
"}",
"\n\n",
"// Get the root iteration",
"itr",
",",
"err",
":=",
"appl",
".",
"Iterations",
"(",
")",
".",
"Root",
"(",
"ctx",
",",
"spaceID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"spaceID",
",",
"\"",
"\"",
":",
"err",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"exp",
"=",
"criteria",
".",
"Equals",
"(",
"criteria",
".",
"Field",
"(",
"workitem",
".",
"SystemIteration",
")",
",",
"criteria",
".",
"Literal",
"(",
"itr",
".",
"ID",
".",
"String",
"(",
")",
")",
")",
"\n\n",
"// Get the list of work item types that derive of PlannerItem in the space",
"var",
"expWits",
"criteria",
".",
"Expression",
"\n",
"wits",
",",
"err",
":=",
"appl",
".",
"WorkItemTypes",
"(",
")",
".",
"ListPlannerItemTypes",
"(",
"ctx",
",",
"space",
".",
"SpaceTemplateID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"wits",
")",
">=",
"1",
"{",
"expWits",
"=",
"criteria",
".",
"Equals",
"(",
"criteria",
".",
"Field",
"(",
"\"",
"\"",
")",
",",
"criteria",
".",
"Literal",
"(",
"wits",
"[",
"0",
"]",
".",
"ID",
".",
"String",
"(",
")",
")",
")",
"\n",
"for",
"_",
",",
"wit",
":=",
"range",
"wits",
"[",
"1",
":",
"]",
"{",
"witIDStr",
":=",
"wit",
".",
"ID",
".",
"String",
"(",
")",
"\n",
"expWits",
"=",
"criteria",
".",
"Or",
"(",
"expWits",
",",
"criteria",
".",
"Equals",
"(",
"criteria",
".",
"Field",
"(",
"\"",
"\"",
")",
",",
"criteria",
".",
"Literal",
"(",
"witIDStr",
")",
")",
")",
"\n",
"}",
"\n",
"exp",
"=",
"criteria",
".",
"And",
"(",
"exp",
",",
"expWits",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"wits",
")",
"==",
"0",
"{",
"// We set exp to nil to return an empty array",
"exp",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"exp",
",",
"nil",
"\n",
"}"
] | // generateBacklogExpression creates the expression to query for backlog items | [
"generateBacklogExpression",
"creates",
"the",
"expression",
"to",
"query",
"for",
"backlog",
"items"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/planner_backlog.go#L79-L128 |
13,483 | fabric8-services/fabric8-wit | controller/users.go | CreateUserAsServiceAccount | func (c *UsersController) CreateUserAsServiceAccount(ctx *app.CreateUserAsServiceAccountUsersContext) error {
isSvcAccount, err := isServiceAccount(ctx, serviceNameAuth)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err))
}
if !isSvcAccount {
log.Error(ctx, map[string]interface{}{
"identity_id": ctx.ID,
}, "account used to call create api is not a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(errs.New("a non-service account tried to create a user.")))
}
return c.createUserInDB(ctx)
} | go | func (c *UsersController) CreateUserAsServiceAccount(ctx *app.CreateUserAsServiceAccountUsersContext) error {
isSvcAccount, err := isServiceAccount(ctx, serviceNameAuth)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err))
}
if !isSvcAccount {
log.Error(ctx, map[string]interface{}{
"identity_id": ctx.ID,
}, "account used to call create api is not a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(errs.New("a non-service account tried to create a user.")))
}
return c.createUserInDB(ctx)
} | [
"func",
"(",
"c",
"*",
"UsersController",
")",
"CreateUserAsServiceAccount",
"(",
"ctx",
"*",
"app",
".",
"CreateUserAsServiceAccountUsersContext",
")",
"error",
"{",
"isSvcAccount",
",",
"err",
":=",
"isServiceAccount",
"(",
"ctx",
",",
"serviceNameAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrUnauthorized",
"(",
"err",
")",
")",
"\n\n",
"}",
"\n",
"if",
"!",
"isSvcAccount",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ctx",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrUnauthorized",
"(",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"createUserInDB",
"(",
"ctx",
")",
"\n",
"}"
] | // CreateUserAsServiceAccount updates a user when requested using a service account token | [
"CreateUserAsServiceAccount",
"updates",
"a",
"user",
"when",
"requested",
"using",
"a",
"service",
"account",
"token"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/users.go#L252-L270 |
13,484 | fabric8-services/fabric8-wit | controller/users.go | UpdateUserAsServiceAccount | func (c *UsersController) UpdateUserAsServiceAccount(ctx *app.UpdateUserAsServiceAccountUsersContext) error {
isSvcAccount, err := isServiceAccount(ctx, serviceNameAuth)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"identity_id": ctx.ID,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err))
}
if !isSvcAccount {
log.Error(ctx, map[string]interface{}{
"identity_id": ctx.ID,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(errs.New("a non-service account tried to updated a user.")))
}
idString := ctx.ID
id, err := uuid.FromString(idString)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrBadRequest(errs.New("incorrect identity")))
}
return c.updateUserInDB(&id, ctx)
} | go | func (c *UsersController) UpdateUserAsServiceAccount(ctx *app.UpdateUserAsServiceAccountUsersContext) error {
isSvcAccount, err := isServiceAccount(ctx, serviceNameAuth)
if err != nil {
log.Error(ctx, map[string]interface{}{
"err": err,
"identity_id": ctx.ID,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err))
}
if !isSvcAccount {
log.Error(ctx, map[string]interface{}{
"identity_id": ctx.ID,
}, "failed to determine if account is a service account")
return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(errs.New("a non-service account tried to updated a user.")))
}
idString := ctx.ID
id, err := uuid.FromString(idString)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, goa.ErrBadRequest(errs.New("incorrect identity")))
}
return c.updateUserInDB(&id, ctx)
} | [
"func",
"(",
"c",
"*",
"UsersController",
")",
"UpdateUserAsServiceAccount",
"(",
"ctx",
"*",
"app",
".",
"UpdateUserAsServiceAccountUsersContext",
")",
"error",
"{",
"isSvcAccount",
",",
"err",
":=",
"isServiceAccount",
"(",
"ctx",
",",
"serviceNameAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"ctx",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrUnauthorized",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"if",
"!",
"isSvcAccount",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ctx",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrUnauthorized",
"(",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"\n\n",
"idString",
":=",
"ctx",
".",
"ID",
"\n",
"id",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"idString",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"jsonapi",
".",
"JSONErrorResponse",
"(",
"ctx",
",",
"goa",
".",
"ErrBadRequest",
"(",
"errs",
".",
"New",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"updateUserInDB",
"(",
"&",
"id",
",",
"ctx",
")",
"\n",
"}"
] | // UpdateUserAsServiceAccount updates a user when requested using a service account token | [
"UpdateUserAsServiceAccount",
"updates",
"a",
"user",
"when",
"requested",
"using",
"a",
"service",
"account",
"token"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/users.go#L362-L385 |
13,485 | fabric8-services/fabric8-wit | controller/users.go | Update | func (c *UsersController) Update(ctx *app.UpdateUsersContext) error {
return proxy.RouteHTTP(ctx, c.config.GetAuthShortServiceHostName())
} | go | func (c *UsersController) Update(ctx *app.UpdateUsersContext) error {
return proxy.RouteHTTP(ctx, c.config.GetAuthShortServiceHostName())
} | [
"func",
"(",
"c",
"*",
"UsersController",
")",
"Update",
"(",
"ctx",
"*",
"app",
".",
"UpdateUsersContext",
")",
"error",
"{",
"return",
"proxy",
".",
"RouteHTTP",
"(",
"ctx",
",",
"c",
".",
"config",
".",
"GetAuthShortServiceHostName",
"(",
")",
")",
"\n",
"}"
] | // Update updates the authorized user based on the provided Token | [
"Update",
"updates",
"the",
"authorized",
"user",
"based",
"on",
"the",
"provided",
"Token"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/controller/users.go#L487-L489 |
13,486 | fabric8-services/fabric8-wit | query/query.go | Create | func (r *GormQueryRepository) Create(ctx context.Context, q *Query) error {
defer goa.MeasureSince([]string{"goa", "db", "Query", "create"}, time.Now())
q.ID = uuid.NewV4()
if q.Creator == uuid.Nil {
return errors.NewBadParameterError("creator cannot be nil", q.Creator).Expected("valid user ID")
}
var v map[string]interface{}
if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
return errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
}
// Parse fields to make sure that query is valid
exp, _, err := search.ParseFilterString(ctx, q.Fields)
if err != nil || exp == nil {
log.Error(ctx, map[string]interface{}{
"space_id": q.SpaceID,
"fields": q.Fields,
}, "unable to parse the query fields")
return err
}
err = r.db.Create(q).Error
if err != nil {
if gormsupport.IsCheckViolation(err, "queries_title_check") {
return errors.NewBadParameterError("Title", q.Title).Expected("not empty")
}
// combination of title, space ID and creator should be unique
if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
log.Error(ctx, map[string]interface{}{
"err": err,
"title": q.Title,
"space_id": q.SpaceID,
}, "unable to create query because a query with same title already exists in the space by same creator")
return errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s, creator = %s", q.Title, q.SpaceID, q.Creator))
}
log.Error(ctx, map[string]interface{}{}, "error adding Query: %s", err.Error())
return err
}
return nil
} | go | func (r *GormQueryRepository) Create(ctx context.Context, q *Query) error {
defer goa.MeasureSince([]string{"goa", "db", "Query", "create"}, time.Now())
q.ID = uuid.NewV4()
if q.Creator == uuid.Nil {
return errors.NewBadParameterError("creator cannot be nil", q.Creator).Expected("valid user ID")
}
var v map[string]interface{}
if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
return errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
}
// Parse fields to make sure that query is valid
exp, _, err := search.ParseFilterString(ctx, q.Fields)
if err != nil || exp == nil {
log.Error(ctx, map[string]interface{}{
"space_id": q.SpaceID,
"fields": q.Fields,
}, "unable to parse the query fields")
return err
}
err = r.db.Create(q).Error
if err != nil {
if gormsupport.IsCheckViolation(err, "queries_title_check") {
return errors.NewBadParameterError("Title", q.Title).Expected("not empty")
}
// combination of title, space ID and creator should be unique
if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
log.Error(ctx, map[string]interface{}{
"err": err,
"title": q.Title,
"space_id": q.SpaceID,
}, "unable to create query because a query with same title already exists in the space by same creator")
return errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s, creator = %s", q.Title, q.SpaceID, q.Creator))
}
log.Error(ctx, map[string]interface{}{}, "error adding Query: %s", err.Error())
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"GormQueryRepository",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"*",
"Query",
")",
"error",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"q",
".",
"ID",
"=",
"uuid",
".",
"NewV4",
"(",
")",
"\n",
"if",
"q",
".",
"Creator",
"==",
"uuid",
".",
"Nil",
"{",
"return",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"q",
".",
"Creator",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"v",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"q",
".",
"Fields",
")",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"q",
".",
"Fields",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Parse fields to make sure that query is valid",
"exp",
",",
"_",
",",
"err",
":=",
"search",
".",
"ParseFilterString",
"(",
"ctx",
",",
"q",
".",
"Fields",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"exp",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"q",
".",
"SpaceID",
",",
"\"",
"\"",
":",
"q",
".",
"Fields",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"r",
".",
"db",
".",
"Create",
"(",
"q",
")",
".",
"Error",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"gormsupport",
".",
"IsCheckViolation",
"(",
"err",
",",
"\"",
"\"",
")",
"{",
"return",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"q",
".",
"Title",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// combination of title, space ID and creator should be unique",
"if",
"gormsupport",
".",
"IsUniqueViolation",
"(",
"err",
",",
"\"",
"\"",
")",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"q",
".",
"Title",
",",
"\"",
"\"",
":",
"q",
".",
"SpaceID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"NewDataConflictError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"Title",
",",
"q",
".",
"SpaceID",
",",
"q",
".",
"Creator",
")",
")",
"\n",
"}",
"\n",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Create a new query | [
"Create",
"a",
"new",
"query"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/query/query.go#L82-L119 |
13,487 | fabric8-services/fabric8-wit | query/query.go | Save | func (r *GormQueryRepository) Save(ctx context.Context, q Query) (*Query, error) {
defer goa.MeasureSince([]string{"goa", "db", "query", "save"}, time.Now())
if strings.TrimSpace(q.Title) == "" {
return nil, errors.NewBadParameterError("query title cannot be empty string", q.Title).Expected("non empty string")
}
var v map[string]interface{}
if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
return nil, errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
}
qry := Query{}
tx := r.db.Where("id = ?", q.ID).First(&qry)
oldVersion := q.Version
q.Version = qry.Version + 1
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
}, "query cannot be found")
return nil, errors.NewNotFoundError("query", q.ID.String())
}
if err := tx.Error; err != nil {
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
"err": err,
}, "unknown error happened when searching the query")
return nil, errors.NewInternalError(ctx, err)
}
tx = tx.Where("Version = ?", oldVersion).Save(&q)
if err := tx.Error; err != nil {
// combination of name and space ID should be unique
if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
log.Error(ctx, map[string]interface{}{
"err": err,
"title": q.Title,
"space_id": q.SpaceID,
}, "unable to create query because a query with same title already exists in the space")
return nil, errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s", q.Title, q.SpaceID.String()))
}
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
"err": err,
}, "unable to save the query")
return nil, errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
return nil, errors.NewVersionConflictError("version conflict")
}
log.Debug(ctx, map[string]interface{}{
"query_id": q.ID,
}, "query updated successfully")
return &q, nil
} | go | func (r *GormQueryRepository) Save(ctx context.Context, q Query) (*Query, error) {
defer goa.MeasureSince([]string{"goa", "db", "query", "save"}, time.Now())
if strings.TrimSpace(q.Title) == "" {
return nil, errors.NewBadParameterError("query title cannot be empty string", q.Title).Expected("non empty string")
}
var v map[string]interface{}
if err := json.Unmarshal([]byte(q.Fields), &v); err != nil {
return nil, errors.NewBadParameterError("query field is invalid JSON syntax", q.Fields).Expected("valid JSON")
}
qry := Query{}
tx := r.db.Where("id = ?", q.ID).First(&qry)
oldVersion := q.Version
q.Version = qry.Version + 1
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
}, "query cannot be found")
return nil, errors.NewNotFoundError("query", q.ID.String())
}
if err := tx.Error; err != nil {
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
"err": err,
}, "unknown error happened when searching the query")
return nil, errors.NewInternalError(ctx, err)
}
tx = tx.Where("Version = ?", oldVersion).Save(&q)
if err := tx.Error; err != nil {
// combination of name and space ID should be unique
if gormsupport.IsUniqueViolation(err, "queries_title_space_id_creator_unique") {
log.Error(ctx, map[string]interface{}{
"err": err,
"title": q.Title,
"space_id": q.SpaceID,
}, "unable to create query because a query with same title already exists in the space")
return nil, errors.NewDataConflictError(fmt.Sprintf("query already exists with title = %s , space_id = %s", q.Title, q.SpaceID.String()))
}
log.Error(ctx, map[string]interface{}{
"query_id": q.ID,
"err": err,
}, "unable to save the query")
return nil, errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
return nil, errors.NewVersionConflictError("version conflict")
}
log.Debug(ctx, map[string]interface{}{
"query_id": q.ID,
}, "query updated successfully")
return &q, nil
} | [
"func",
"(",
"r",
"*",
"GormQueryRepository",
")",
"Save",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"*",
"Query",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"if",
"strings",
".",
"TrimSpace",
"(",
"q",
".",
"Title",
")",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"q",
".",
"Title",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"v",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"q",
".",
"Fields",
")",
",",
"&",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"q",
".",
"Fields",
")",
".",
"Expected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"qry",
":=",
"Query",
"{",
"}",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Where",
"(",
"\"",
"\"",
",",
"q",
".",
"ID",
")",
".",
"First",
"(",
"&",
"qry",
")",
"\n",
"oldVersion",
":=",
"q",
".",
"Version",
"\n",
"q",
".",
"Version",
"=",
"qry",
".",
"Version",
"+",
"1",
"\n",
"if",
"tx",
".",
"RecordNotFound",
"(",
")",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"q",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"q",
".",
"ID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"tx",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"q",
".",
"ID",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"tx",
"=",
"tx",
".",
"Where",
"(",
"\"",
"\"",
",",
"oldVersion",
")",
".",
"Save",
"(",
"&",
"q",
")",
"\n",
"if",
"err",
":=",
"tx",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"// combination of name and space ID should be unique",
"if",
"gormsupport",
".",
"IsUniqueViolation",
"(",
"err",
",",
"\"",
"\"",
")",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"q",
".",
"Title",
",",
"\"",
"\"",
":",
"q",
".",
"SpaceID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewDataConflictError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"Title",
",",
"q",
".",
"SpaceID",
".",
"String",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"q",
".",
"ID",
",",
"\"",
"\"",
":",
"err",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"tx",
".",
"RowsAffected",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"NewVersionConflictError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"q",
".",
"ID",
",",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"&",
"q",
",",
"nil",
"\n",
"}"
] | // Save update the given query | [
"Save",
"update",
"the",
"given",
"query"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/query/query.go#L122-L173 |
13,488 | fabric8-services/fabric8-wit | query/query.go | Load | func (r *GormQueryRepository) Load(ctx context.Context, ID uuid.UUID, spaceID uuid.UUID) (*Query, error) {
defer goa.MeasureSince([]string{"goa", "db", "query", "show"}, time.Now())
q := Query{}
tx := r.db.Where("id = ? and space_id = ?", ID, spaceID).First(&q)
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "record not found")
return nil, errors.NewNotFoundError("query", ID.String())
}
if tx.Error != nil {
log.Error(ctx, map[string]interface{}{
"err": tx.Error,
"query_id": ID.String(),
}, "unable to load the query by ID")
return nil, errors.NewInternalError(ctx, tx.Error)
}
return &q, nil
} | go | func (r *GormQueryRepository) Load(ctx context.Context, ID uuid.UUID, spaceID uuid.UUID) (*Query, error) {
defer goa.MeasureSince([]string{"goa", "db", "query", "show"}, time.Now())
q := Query{}
tx := r.db.Where("id = ? and space_id = ?", ID, spaceID).First(&q)
if tx.RecordNotFound() {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "record not found")
return nil, errors.NewNotFoundError("query", ID.String())
}
if tx.Error != nil {
log.Error(ctx, map[string]interface{}{
"err": tx.Error,
"query_id": ID.String(),
}, "unable to load the query by ID")
return nil, errors.NewInternalError(ctx, tx.Error)
}
return &q, nil
} | [
"func",
"(",
"r",
"*",
"GormQueryRepository",
")",
"Load",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"uuid",
".",
"UUID",
",",
"spaceID",
"uuid",
".",
"UUID",
")",
"(",
"*",
"Query",
",",
"error",
")",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"q",
":=",
"Query",
"{",
"}",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Where",
"(",
"\"",
"\"",
",",
"ID",
",",
"spaceID",
")",
".",
"First",
"(",
"&",
"q",
")",
"\n",
"if",
"tx",
".",
"RecordNotFound",
"(",
")",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ID",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"ID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"tx",
".",
"Error",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"tx",
".",
"Error",
",",
"\"",
"\"",
":",
"ID",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"tx",
".",
"Error",
")",
"\n",
"}",
"\n",
"return",
"&",
"q",
",",
"nil",
"\n",
"}"
] | // Load Query in a space | [
"Load",
"Query",
"in",
"a",
"space"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/query/query.go#L198-L216 |
13,489 | fabric8-services/fabric8-wit | query/query.go | Delete | func (r *GormQueryRepository) Delete(ctx context.Context, ID uuid.UUID) error {
defer goa.MeasureSince([]string{"goa", "db", "query", "delete"}, time.Now())
q := Query{ID: ID}
tx := r.db.Delete(q)
if err := tx.Error; err != nil {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "unable to delete the query")
return errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "no row was affected by the delete operation")
return errors.NewNotFoundError("query", ID.String())
}
return nil
} | go | func (r *GormQueryRepository) Delete(ctx context.Context, ID uuid.UUID) error {
defer goa.MeasureSince([]string{"goa", "db", "query", "delete"}, time.Now())
q := Query{ID: ID}
tx := r.db.Delete(q)
if err := tx.Error; err != nil {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "unable to delete the query")
return errors.NewInternalError(ctx, err)
}
if tx.RowsAffected == 0 {
log.Error(ctx, map[string]interface{}{
"query_id": ID.String(),
}, "no row was affected by the delete operation")
return errors.NewNotFoundError("query", ID.String())
}
return nil
} | [
"func",
"(",
"r",
"*",
"GormQueryRepository",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"uuid",
".",
"UUID",
")",
"error",
"{",
"defer",
"goa",
".",
"MeasureSince",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"time",
".",
"Now",
"(",
")",
")",
"\n",
"q",
":=",
"Query",
"{",
"ID",
":",
"ID",
"}",
"\n",
"tx",
":=",
"r",
".",
"db",
".",
"Delete",
"(",
"q",
")",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ID",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"NewInternalError",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"tx",
".",
"RowsAffected",
"==",
"0",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ID",
".",
"String",
"(",
")",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"NewNotFoundError",
"(",
"\"",
"\"",
",",
"ID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete deletes the query with the given id, returns NotFoundError or InternalError | [
"Delete",
"deletes",
"the",
"query",
"with",
"the",
"given",
"id",
"returns",
"NotFoundError",
"or",
"InternalError"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/query/query.go#L219-L237 |
13,490 | fabric8-services/fabric8-wit | rest/proxy/error.go | ConvertHTTPErrorCode | func ConvertHTTPErrorCode(statusCode int, responseBody string) error {
switch statusCode {
case http.StatusNotFound:
return errors.NewNotFoundErrorFromString(responseBody)
case http.StatusBadRequest:
return errors.NewBadParameterErrorFromString(responseBody)
case http.StatusConflict:
return errors.NewDataConflictError(responseBody)
case http.StatusUnauthorized:
return errors.NewUnauthorizedError(responseBody)
case http.StatusForbidden:
return errors.NewForbiddenError(responseBody)
default:
return errors.NewInternalErrorFromString(responseBody)
}
} | go | func ConvertHTTPErrorCode(statusCode int, responseBody string) error {
switch statusCode {
case http.StatusNotFound:
return errors.NewNotFoundErrorFromString(responseBody)
case http.StatusBadRequest:
return errors.NewBadParameterErrorFromString(responseBody)
case http.StatusConflict:
return errors.NewDataConflictError(responseBody)
case http.StatusUnauthorized:
return errors.NewUnauthorizedError(responseBody)
case http.StatusForbidden:
return errors.NewForbiddenError(responseBody)
default:
return errors.NewInternalErrorFromString(responseBody)
}
} | [
"func",
"ConvertHTTPErrorCode",
"(",
"statusCode",
"int",
",",
"responseBody",
"string",
")",
"error",
"{",
"switch",
"statusCode",
"{",
"case",
"http",
".",
"StatusNotFound",
":",
"return",
"errors",
".",
"NewNotFoundErrorFromString",
"(",
"responseBody",
")",
"\n\n",
"case",
"http",
".",
"StatusBadRequest",
":",
"return",
"errors",
".",
"NewBadParameterErrorFromString",
"(",
"responseBody",
")",
"\n\n",
"case",
"http",
".",
"StatusConflict",
":",
"return",
"errors",
".",
"NewDataConflictError",
"(",
"responseBody",
")",
"\n\n",
"case",
"http",
".",
"StatusUnauthorized",
":",
"return",
"errors",
".",
"NewUnauthorizedError",
"(",
"responseBody",
")",
"\n\n",
"case",
"http",
".",
"StatusForbidden",
":",
"return",
"errors",
".",
"NewForbiddenError",
"(",
"responseBody",
")",
"\n\n",
"default",
":",
"return",
"errors",
".",
"NewInternalErrorFromString",
"(",
"responseBody",
")",
"\n",
"}",
"\n",
"}"
] | // ConvertHTTPErrorCode converts an http status code to an instance of type error | [
"ConvertHTTPErrorCode",
"converts",
"an",
"http",
"status",
"code",
"to",
"an",
"instance",
"of",
"type",
"error"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/rest/proxy/error.go#L9-L31 |
13,491 | fabric8-services/fabric8-wit | token/token.go | NewManager | func NewManager(config tokenManagerConfiguration) (Manager, error) {
// Load public keys from Auth service and add them to the manager
tm := &tokenManager{
publicKeysMap: map[string]*rsa.PublicKey{},
}
keysEndpoint := fmt.Sprintf("%s%s", config.GetAuthServiceURL(), authservice.KeysTokenPath())
remoteKeys, err := authjwk.FetchKeys(keysEndpoint)
if err != nil {
log.Error(nil, map[string]interface{}{
"err": err,
"keys_url": keysEndpoint,
}, "unable to load public keys from remote service")
return nil, errors.New("unable to load public keys from remote service")
}
for _, remoteKey := range remoteKeys {
tm.publicKeysMap[remoteKey.KeyID] = remoteKey.Key
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: remoteKey.KeyID, Key: remoteKey.Key})
log.Info(nil, map[string]interface{}{
"kid": remoteKey.KeyID,
}, "Public key added")
}
devModeURL := config.GetKeycloakDevModeURL()
if devModeURL != "" {
remoteKeys, err = authjwk.FetchKeys(fmt.Sprintf("%s/protocol/openid-connect/certs", devModeURL))
if err != nil {
log.Error(nil, map[string]interface{}{
"err": err,
"keys_url": devModeURL,
}, "unable to load public keys from remote service in Dev Mode")
return nil, errors.New("unable to load public keys from remote service in Dev Mode")
}
for _, remoteKey := range remoteKeys {
tm.publicKeysMap[remoteKey.KeyID] = remoteKey.Key
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: remoteKey.KeyID, Key: remoteKey.Key})
log.Info(nil, map[string]interface{}{
"kid": remoteKey.KeyID,
}, "Public key added")
}
// Add the public key which will be used to verify tokens generated in dev mode
rsaKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(configuration.DevModeRsaPrivateKey))
if err != nil {
return nil, err
}
tm.publicKeysMap["test-key"] = &rsaKey.PublicKey
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: "test-key", Key: &rsaKey.PublicKey})
log.Info(nil, map[string]interface{}{
"kid": "test-key",
}, "Public key added")
}
return tm, nil
} | go | func NewManager(config tokenManagerConfiguration) (Manager, error) {
// Load public keys from Auth service and add them to the manager
tm := &tokenManager{
publicKeysMap: map[string]*rsa.PublicKey{},
}
keysEndpoint := fmt.Sprintf("%s%s", config.GetAuthServiceURL(), authservice.KeysTokenPath())
remoteKeys, err := authjwk.FetchKeys(keysEndpoint)
if err != nil {
log.Error(nil, map[string]interface{}{
"err": err,
"keys_url": keysEndpoint,
}, "unable to load public keys from remote service")
return nil, errors.New("unable to load public keys from remote service")
}
for _, remoteKey := range remoteKeys {
tm.publicKeysMap[remoteKey.KeyID] = remoteKey.Key
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: remoteKey.KeyID, Key: remoteKey.Key})
log.Info(nil, map[string]interface{}{
"kid": remoteKey.KeyID,
}, "Public key added")
}
devModeURL := config.GetKeycloakDevModeURL()
if devModeURL != "" {
remoteKeys, err = authjwk.FetchKeys(fmt.Sprintf("%s/protocol/openid-connect/certs", devModeURL))
if err != nil {
log.Error(nil, map[string]interface{}{
"err": err,
"keys_url": devModeURL,
}, "unable to load public keys from remote service in Dev Mode")
return nil, errors.New("unable to load public keys from remote service in Dev Mode")
}
for _, remoteKey := range remoteKeys {
tm.publicKeysMap[remoteKey.KeyID] = remoteKey.Key
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: remoteKey.KeyID, Key: remoteKey.Key})
log.Info(nil, map[string]interface{}{
"kid": remoteKey.KeyID,
}, "Public key added")
}
// Add the public key which will be used to verify tokens generated in dev mode
rsaKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(configuration.DevModeRsaPrivateKey))
if err != nil {
return nil, err
}
tm.publicKeysMap["test-key"] = &rsaKey.PublicKey
tm.publicKeys = append(tm.publicKeys, &PublicKey{KeyID: "test-key", Key: &rsaKey.PublicKey})
log.Info(nil, map[string]interface{}{
"kid": "test-key",
}, "Public key added")
}
return tm, nil
} | [
"func",
"NewManager",
"(",
"config",
"tokenManagerConfiguration",
")",
"(",
"Manager",
",",
"error",
")",
"{",
"// Load public keys from Auth service and add them to the manager",
"tm",
":=",
"&",
"tokenManager",
"{",
"publicKeysMap",
":",
"map",
"[",
"string",
"]",
"*",
"rsa",
".",
"PublicKey",
"{",
"}",
",",
"}",
"\n\n",
"keysEndpoint",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"config",
".",
"GetAuthServiceURL",
"(",
")",
",",
"authservice",
".",
"KeysTokenPath",
"(",
")",
")",
"\n",
"remoteKeys",
",",
"err",
":=",
"authjwk",
".",
"FetchKeys",
"(",
"keysEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"keysEndpoint",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"remoteKey",
":=",
"range",
"remoteKeys",
"{",
"tm",
".",
"publicKeysMap",
"[",
"remoteKey",
".",
"KeyID",
"]",
"=",
"remoteKey",
".",
"Key",
"\n",
"tm",
".",
"publicKeys",
"=",
"append",
"(",
"tm",
".",
"publicKeys",
",",
"&",
"PublicKey",
"{",
"KeyID",
":",
"remoteKey",
".",
"KeyID",
",",
"Key",
":",
"remoteKey",
".",
"Key",
"}",
")",
"\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"remoteKey",
".",
"KeyID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"devModeURL",
":=",
"config",
".",
"GetKeycloakDevModeURL",
"(",
")",
"\n",
"if",
"devModeURL",
"!=",
"\"",
"\"",
"{",
"remoteKeys",
",",
"err",
"=",
"authjwk",
".",
"FetchKeys",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"devModeURL",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"err",
",",
"\"",
"\"",
":",
"devModeURL",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"remoteKey",
":=",
"range",
"remoteKeys",
"{",
"tm",
".",
"publicKeysMap",
"[",
"remoteKey",
".",
"KeyID",
"]",
"=",
"remoteKey",
".",
"Key",
"\n",
"tm",
".",
"publicKeys",
"=",
"append",
"(",
"tm",
".",
"publicKeys",
",",
"&",
"PublicKey",
"{",
"KeyID",
":",
"remoteKey",
".",
"KeyID",
",",
"Key",
":",
"remoteKey",
".",
"Key",
"}",
")",
"\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"remoteKey",
".",
"KeyID",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Add the public key which will be used to verify tokens generated in dev mode",
"rsaKey",
",",
"err",
":=",
"jwt",
".",
"ParseRSAPrivateKeyFromPEM",
"(",
"[",
"]",
"byte",
"(",
"configuration",
".",
"DevModeRsaPrivateKey",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tm",
".",
"publicKeysMap",
"[",
"\"",
"\"",
"]",
"=",
"&",
"rsaKey",
".",
"PublicKey",
"\n",
"tm",
".",
"publicKeys",
"=",
"append",
"(",
"tm",
".",
"publicKeys",
",",
"&",
"PublicKey",
"{",
"KeyID",
":",
"\"",
"\"",
",",
"Key",
":",
"&",
"rsaKey",
".",
"PublicKey",
"}",
")",
"\n",
"log",
".",
"Info",
"(",
"nil",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"tm",
",",
"nil",
"\n",
"}"
] | // NewManager returns a new token Manager for handling tokens | [
"NewManager",
"returns",
"a",
"new",
"token",
"Manager",
"for",
"handling",
"tokens"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/token/token.go#L70-L123 |
13,492 | fabric8-services/fabric8-wit | token/token.go | NewManagerWithPublicKey | func NewManagerWithPublicKey(id string, key *rsa.PublicKey) Manager {
return &tokenManager{
publicKeysMap: map[string]*rsa.PublicKey{id: key},
publicKeys: []*PublicKey{{KeyID: id, Key: key}},
}
} | go | func NewManagerWithPublicKey(id string, key *rsa.PublicKey) Manager {
return &tokenManager{
publicKeysMap: map[string]*rsa.PublicKey{id: key},
publicKeys: []*PublicKey{{KeyID: id, Key: key}},
}
} | [
"func",
"NewManagerWithPublicKey",
"(",
"id",
"string",
",",
"key",
"*",
"rsa",
".",
"PublicKey",
")",
"Manager",
"{",
"return",
"&",
"tokenManager",
"{",
"publicKeysMap",
":",
"map",
"[",
"string",
"]",
"*",
"rsa",
".",
"PublicKey",
"{",
"id",
":",
"key",
"}",
",",
"publicKeys",
":",
"[",
"]",
"*",
"PublicKey",
"{",
"{",
"KeyID",
":",
"id",
",",
"Key",
":",
"key",
"}",
"}",
",",
"}",
"\n",
"}"
] | // NewManagerWithPublicKey returns a new token Manager for handling tokens with the only public key | [
"NewManagerWithPublicKey",
"returns",
"a",
"new",
"token",
"Manager",
"for",
"handling",
"tokens",
"with",
"the",
"only",
"public",
"key"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/token/token.go#L126-L131 |
13,493 | fabric8-services/fabric8-wit | token/token.go | ParseToken | func (mgm *tokenManager) ParseToken(ctx context.Context, tokenString string) (*TokenClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &TokenClaims{}, func(token *jwt.Token) (interface{}, error) {
kid, ok := token.Header["kid"]
if !ok {
log.Error(ctx, map[string]interface{}{}, "There is no 'kid' header in the token")
return nil, errors.New("there is no 'kid' header in the token")
}
key := mgm.PublicKey(fmt.Sprintf("%s", kid))
if key == nil {
log.Error(ctx, map[string]interface{}{
"kid": kid,
}, "There is no public key with such ID")
return nil, errors.Errorf("there is no public key with such ID: %s", kid)
}
return key, nil
})
if err != nil {
return nil, err
}
claims := token.Claims.(*TokenClaims)
if token.Valid {
return claims, nil
}
return nil, errors.WithStack(errors.New("token is not valid"))
} | go | func (mgm *tokenManager) ParseToken(ctx context.Context, tokenString string) (*TokenClaims, error) {
token, err := jwt.ParseWithClaims(tokenString, &TokenClaims{}, func(token *jwt.Token) (interface{}, error) {
kid, ok := token.Header["kid"]
if !ok {
log.Error(ctx, map[string]interface{}{}, "There is no 'kid' header in the token")
return nil, errors.New("there is no 'kid' header in the token")
}
key := mgm.PublicKey(fmt.Sprintf("%s", kid))
if key == nil {
log.Error(ctx, map[string]interface{}{
"kid": kid,
}, "There is no public key with such ID")
return nil, errors.Errorf("there is no public key with such ID: %s", kid)
}
return key, nil
})
if err != nil {
return nil, err
}
claims := token.Claims.(*TokenClaims)
if token.Valid {
return claims, nil
}
return nil, errors.WithStack(errors.New("token is not valid"))
} | [
"func",
"(",
"mgm",
"*",
"tokenManager",
")",
"ParseToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"tokenString",
"string",
")",
"(",
"*",
"TokenClaims",
",",
"error",
")",
"{",
"token",
",",
"err",
":=",
"jwt",
".",
"ParseWithClaims",
"(",
"tokenString",
",",
"&",
"TokenClaims",
"{",
"}",
",",
"func",
"(",
"token",
"*",
"jwt",
".",
"Token",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"kid",
",",
"ok",
":=",
"token",
".",
"Header",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"key",
":=",
"mgm",
".",
"PublicKey",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"kid",
")",
")",
"\n",
"if",
"key",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"kid",
",",
"}",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"kid",
")",
"\n",
"}",
"\n",
"return",
"key",
",",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"claims",
":=",
"token",
".",
"Claims",
".",
"(",
"*",
"TokenClaims",
")",
"\n",
"if",
"token",
".",
"Valid",
"{",
"return",
"claims",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"WithStack",
"(",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // ParseToken parses token claims | [
"ParseToken",
"parses",
"token",
"claims"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/token/token.go#L149-L173 |
13,494 | fabric8-services/fabric8-wit | token/token.go | CheckClaims | func CheckClaims(claims *TokenClaims) error {
if claims.Subject == "" {
return errors.New("subject claim not found in token")
}
_, err := uuid.FromString(claims.Subject)
if err != nil {
return errors.New("subject claim from token is not UUID " + err.Error())
}
if claims.Username == "" {
return errors.New("username claim not found in token")
}
if claims.Email == "" {
return errors.New("email claim not found in token")
}
return nil
} | go | func CheckClaims(claims *TokenClaims) error {
if claims.Subject == "" {
return errors.New("subject claim not found in token")
}
_, err := uuid.FromString(claims.Subject)
if err != nil {
return errors.New("subject claim from token is not UUID " + err.Error())
}
if claims.Username == "" {
return errors.New("username claim not found in token")
}
if claims.Email == "" {
return errors.New("email claim not found in token")
}
return nil
} | [
"func",
"CheckClaims",
"(",
"claims",
"*",
"TokenClaims",
")",
"error",
"{",
"if",
"claims",
".",
"Subject",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"uuid",
".",
"FromString",
"(",
"claims",
".",
"Subject",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"claims",
".",
"Username",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"claims",
".",
"Email",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckClaims checks if all the required claims are present in the access token | [
"CheckClaims",
"checks",
"if",
"all",
"the",
"required",
"claims",
"are",
"present",
"in",
"the",
"access",
"token"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/token/token.go#L206-L221 |
13,495 | fabric8-services/fabric8-wit | token/token.go | ReadManagerFromContext | func ReadManagerFromContext(ctx context.Context) (*Manager, error) {
tm := tokencontext.ReadTokenManagerFromContext(ctx)
if tm == nil {
log.Error(ctx, map[string]interface{}{
"token": tm,
}, "missing token manager")
return nil, errors.New("Missing token manager")
}
tokenManager := tm.(Manager)
return &tokenManager, nil
} | go | func ReadManagerFromContext(ctx context.Context) (*Manager, error) {
tm := tokencontext.ReadTokenManagerFromContext(ctx)
if tm == nil {
log.Error(ctx, map[string]interface{}{
"token": tm,
}, "missing token manager")
return nil, errors.New("Missing token manager")
}
tokenManager := tm.(Manager)
return &tokenManager, nil
} | [
"func",
"ReadManagerFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Manager",
",",
"error",
")",
"{",
"tm",
":=",
"tokencontext",
".",
"ReadTokenManagerFromContext",
"(",
"ctx",
")",
"\n",
"if",
"tm",
"==",
"nil",
"{",
"log",
".",
"Error",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"tm",
",",
"}",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"tokenManager",
":=",
"tm",
".",
"(",
"Manager",
")",
"\n",
"return",
"&",
"tokenManager",
",",
"nil",
"\n",
"}"
] | // ReadManagerFromContext extracts the token manager from the context | [
"ReadManagerFromContext",
"extracts",
"the",
"token",
"manager",
"from",
"the",
"context"
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/token/token.go#L224-L235 |
13,496 | fabric8-services/fabric8-wit | iteration/state.go | CheckValid | func (s State) CheckValid() error {
switch s {
case StateNew, StateStart, StateClose:
return nil
default:
return errors.NewBadParameterError("iteration state", s).Expected(StateNew + "|" + StateStart + "|" + StateClose)
}
} | go | func (s State) CheckValid() error {
switch s {
case StateNew, StateStart, StateClose:
return nil
default:
return errors.NewBadParameterError("iteration state", s).Expected(StateNew + "|" + StateStart + "|" + StateClose)
}
} | [
"func",
"(",
"s",
"State",
")",
"CheckValid",
"(",
")",
"error",
"{",
"switch",
"s",
"{",
"case",
"StateNew",
",",
"StateStart",
",",
"StateClose",
":",
"return",
"nil",
"\n",
"default",
":",
"return",
"errors",
".",
"NewBadParameterError",
"(",
"\"",
"\"",
",",
"s",
")",
".",
"Expected",
"(",
"StateNew",
"+",
"\"",
"\"",
"+",
"StateStart",
"+",
"\"",
"\"",
"+",
"StateClose",
")",
"\n",
"}",
"\n",
"}"
] | // CheckValid returns nil if the given iteration state is valid; otherwise a
// BadParameterError is returned. | [
"CheckValid",
"returns",
"nil",
"if",
"the",
"given",
"iteration",
"state",
"is",
"valid",
";",
"otherwise",
"a",
"BadParameterError",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/iteration/state.go#L58-L65 |
13,497 | fabric8-services/fabric8-wit | workitem/workitemtype.go | Validate | func (wit WorkItemType) Validate() error {
if strings.TrimSpace(wit.Name) == "" {
return errs.Errorf(`work item type name "%s" when trimmed has a zero-length`, wit.Name)
}
if err := wit.Fields.Validate(); err != nil {
return errs.Wrapf(err, "failed to validate work item type's fields")
}
return nil
} | go | func (wit WorkItemType) Validate() error {
if strings.TrimSpace(wit.Name) == "" {
return errs.Errorf(`work item type name "%s" when trimmed has a zero-length`, wit.Name)
}
if err := wit.Fields.Validate(); err != nil {
return errs.Wrapf(err, "failed to validate work item type's fields")
}
return nil
} | [
"func",
"(",
"wit",
"WorkItemType",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"wit",
".",
"Name",
")",
"==",
"\"",
"\"",
"{",
"return",
"errs",
".",
"Errorf",
"(",
"`work item type name \"%s\" when trimmed has a zero-length`",
",",
"wit",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"wit",
".",
"Fields",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate runs some checks on the work item type to ensure the field
// definitions make sense. | [
"Validate",
"runs",
"some",
"checks",
"on",
"the",
"work",
"item",
"type",
"to",
"ensure",
"the",
"field",
"definitions",
"make",
"sense",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype.go#L120-L128 |
13,498 | fabric8-services/fabric8-wit | workitem/workitemtype.go | strPtrIsNilOrContentIsEqual | func strPtrIsNilOrContentIsEqual(l, r *string) bool {
if l == nil && r != nil {
return false
}
if l != nil && r == nil {
return false
}
if l == nil && r == nil {
return true
}
return *l == *r
} | go | func strPtrIsNilOrContentIsEqual(l, r *string) bool {
if l == nil && r != nil {
return false
}
if l != nil && r == nil {
return false
}
if l == nil && r == nil {
return true
}
return *l == *r
} | [
"func",
"strPtrIsNilOrContentIsEqual",
"(",
"l",
",",
"r",
"*",
"string",
")",
"bool",
"{",
"if",
"l",
"==",
"nil",
"&&",
"r",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"l",
"!=",
"nil",
"&&",
"r",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"l",
"==",
"nil",
"&&",
"r",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"*",
"l",
"==",
"*",
"r",
"\n",
"}"
] | // returns true if the left hand and right hand side string
// pointers either both point to nil or reference the same
// content; otherwise false is returned. | [
"returns",
"true",
"if",
"the",
"left",
"hand",
"and",
"right",
"hand",
"side",
"string",
"pointers",
"either",
"both",
"point",
"to",
"nil",
"or",
"reference",
"the",
"same",
"content",
";",
"otherwise",
"false",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype.go#L159-L170 |
13,499 | fabric8-services/fabric8-wit | workitem/workitemtype.go | Equal | func (wit WorkItemType) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemType)
if !ok {
return false
}
if wit.ID != other.ID {
return false
}
if !convert.CascadeEqual(wit.Lifecycle, other.Lifecycle) {
return false
}
if wit.Version != other.Version {
return false
}
if wit.Name != other.Name {
return false
}
if wit.Extends != other.Extends {
return false
}
if wit.CanConstruct != other.CanConstruct {
return false
}
if !reflect.DeepEqual(wit.Description, other.Description) {
return false
}
if wit.Icon != other.Icon {
return false
}
if wit.Path != other.Path {
return false
}
if len(wit.ChildTypeIDs) != len(other.ChildTypeIDs) {
return false
}
for i := range wit.ChildTypeIDs {
if wit.ChildTypeIDs[i] != other.ChildTypeIDs[i] {
return false
}
}
if len(wit.Fields) != len(other.Fields) {
return false
}
for witKey, witVal := range wit.Fields {
otherVal, keyFound := other.Fields[witKey]
if !keyFound {
return false
}
if !convert.CascadeEqual(witVal, otherVal) {
return false
}
}
if wit.SpaceTemplateID != other.SpaceTemplateID {
return false
}
return true
} | go | func (wit WorkItemType) Equal(u convert.Equaler) bool {
other, ok := u.(WorkItemType)
if !ok {
return false
}
if wit.ID != other.ID {
return false
}
if !convert.CascadeEqual(wit.Lifecycle, other.Lifecycle) {
return false
}
if wit.Version != other.Version {
return false
}
if wit.Name != other.Name {
return false
}
if wit.Extends != other.Extends {
return false
}
if wit.CanConstruct != other.CanConstruct {
return false
}
if !reflect.DeepEqual(wit.Description, other.Description) {
return false
}
if wit.Icon != other.Icon {
return false
}
if wit.Path != other.Path {
return false
}
if len(wit.ChildTypeIDs) != len(other.ChildTypeIDs) {
return false
}
for i := range wit.ChildTypeIDs {
if wit.ChildTypeIDs[i] != other.ChildTypeIDs[i] {
return false
}
}
if len(wit.Fields) != len(other.Fields) {
return false
}
for witKey, witVal := range wit.Fields {
otherVal, keyFound := other.Fields[witKey]
if !keyFound {
return false
}
if !convert.CascadeEqual(witVal, otherVal) {
return false
}
}
if wit.SpaceTemplateID != other.SpaceTemplateID {
return false
}
return true
} | [
"func",
"(",
"wit",
"WorkItemType",
")",
"Equal",
"(",
"u",
"convert",
".",
"Equaler",
")",
"bool",
"{",
"other",
",",
"ok",
":=",
"u",
".",
"(",
"WorkItemType",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"ID",
"!=",
"other",
".",
"ID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"convert",
".",
"CascadeEqual",
"(",
"wit",
".",
"Lifecycle",
",",
"other",
".",
"Lifecycle",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"Version",
"!=",
"other",
".",
"Version",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"Name",
"!=",
"other",
".",
"Name",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"Extends",
"!=",
"other",
".",
"Extends",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"CanConstruct",
"!=",
"other",
".",
"CanConstruct",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"wit",
".",
"Description",
",",
"other",
".",
"Description",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"Icon",
"!=",
"other",
".",
"Icon",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"wit",
".",
"Path",
"!=",
"other",
".",
"Path",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"wit",
".",
"ChildTypeIDs",
")",
"!=",
"len",
"(",
"other",
".",
"ChildTypeIDs",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"wit",
".",
"ChildTypeIDs",
"{",
"if",
"wit",
".",
"ChildTypeIDs",
"[",
"i",
"]",
"!=",
"other",
".",
"ChildTypeIDs",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"wit",
".",
"Fields",
")",
"!=",
"len",
"(",
"other",
".",
"Fields",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"witKey",
",",
"witVal",
":=",
"range",
"wit",
".",
"Fields",
"{",
"otherVal",
",",
"keyFound",
":=",
"other",
".",
"Fields",
"[",
"witKey",
"]",
"\n",
"if",
"!",
"keyFound",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"convert",
".",
"CascadeEqual",
"(",
"witVal",
",",
"otherVal",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"wit",
".",
"SpaceTemplateID",
"!=",
"other",
".",
"SpaceTemplateID",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Equal returns true if two WorkItemType objects are equal; otherwise false is returned. | [
"Equal",
"returns",
"true",
"if",
"two",
"WorkItemType",
"objects",
"are",
"equal",
";",
"otherwise",
"false",
"is",
"returned",
"."
] | 54759c80c42ff2cf29b352e0f6c9330ce4ad7fce | https://github.com/fabric8-services/fabric8-wit/blob/54759c80c42ff2cf29b352e0f6c9330ce4ad7fce/workitem/workitemtype.go#L173-L229 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.