repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
JobParameterized
|
func (c *Client) JobParameterized(jobInfo *JobInfo) bool {
for _, prop := range jobInfo.Property {
if prop.ParameterDefinitions != nil && len(prop.ParameterDefinitions) > 0 {
return true
}
}
return false
}
|
go
|
func (c *Client) JobParameterized(jobInfo *JobInfo) bool {
for _, prop := range jobInfo.Property {
if prop.ParameterDefinitions != nil && len(prop.ParameterDefinitions) > 0 {
return true
}
}
return false
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"JobParameterized",
"(",
"jobInfo",
"*",
"JobInfo",
")",
"bool",
"{",
"for",
"_",
",",
"prop",
":=",
"range",
"jobInfo",
".",
"Property",
"{",
"if",
"prop",
".",
"ParameterDefinitions",
"!=",
"nil",
"&&",
"len",
"(",
"prop",
".",
"ParameterDefinitions",
")",
">",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// JobParameterized tells us if the Jenkins job for this ProwJob is parameterized
|
[
"JobParameterized",
"tells",
"us",
"if",
"the",
"Jenkins",
"job",
"for",
"this",
"ProwJob",
"is",
"parameterized"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L483-L491
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
EnsureBuildableJob
|
func (c *Client) EnsureBuildableJob(spec *prowapi.ProwJobSpec) error {
var jobInfo *JobInfo
// wait at most 20 seconds for the job to appear
getJobInfoBackoff := wait.Backoff{
Duration: time.Duration(10) * time.Second,
Factor: 1,
Jitter: 0,
Steps: 2,
}
getJobErr := wait.ExponentialBackoff(getJobInfoBackoff, func() (bool, error) {
var jobErr error
jobInfo, jobErr = c.GetJobInfo(spec)
if jobErr != nil && !strings.Contains(strings.ToLower(jobErr.Error()), "404 not found") {
return false, jobErr
}
return jobInfo != nil, nil
})
if getJobErr != nil {
return fmt.Errorf("Job %v does not exist", spec.Job)
}
isParameterized := c.JobParameterized(jobInfo)
c.logger.Tracef("JobHasParameters: %v", isParameterized)
if isParameterized || len(jobInfo.Builds) > 0 {
return nil
}
buildErr := c.LaunchBuild(spec, nil)
if buildErr != nil {
return buildErr
}
backoff := wait.Backoff{
Duration: time.Duration(5) * time.Second,
Factor: 1,
Jitter: 1,
Steps: 10,
}
return wait.ExponentialBackoff(backoff, func() (bool, error) {
c.logger.Debugf("Waiting for job %v to become parameterized", spec.Job)
jobInfo, _ := c.GetJobInfo(spec)
isParameterized := false
if jobInfo != nil {
isParameterized = c.JobParameterized(jobInfo)
if isParameterized && jobInfo.LastBuild != nil {
c.logger.Debugf("Job %v is now parameterized, aborting the build", spec.Job)
err := c.Abort(getJobName(spec), jobInfo.LastBuild)
if err != nil {
c.logger.Infof("Couldn't abort build #%v for job %v: %v", jobInfo.LastBuild.Number, spec.Job, err)
}
}
}
// don't stop on (possibly) intermittent errors
return isParameterized, nil
})
}
|
go
|
func (c *Client) EnsureBuildableJob(spec *prowapi.ProwJobSpec) error {
var jobInfo *JobInfo
// wait at most 20 seconds for the job to appear
getJobInfoBackoff := wait.Backoff{
Duration: time.Duration(10) * time.Second,
Factor: 1,
Jitter: 0,
Steps: 2,
}
getJobErr := wait.ExponentialBackoff(getJobInfoBackoff, func() (bool, error) {
var jobErr error
jobInfo, jobErr = c.GetJobInfo(spec)
if jobErr != nil && !strings.Contains(strings.ToLower(jobErr.Error()), "404 not found") {
return false, jobErr
}
return jobInfo != nil, nil
})
if getJobErr != nil {
return fmt.Errorf("Job %v does not exist", spec.Job)
}
isParameterized := c.JobParameterized(jobInfo)
c.logger.Tracef("JobHasParameters: %v", isParameterized)
if isParameterized || len(jobInfo.Builds) > 0 {
return nil
}
buildErr := c.LaunchBuild(spec, nil)
if buildErr != nil {
return buildErr
}
backoff := wait.Backoff{
Duration: time.Duration(5) * time.Second,
Factor: 1,
Jitter: 1,
Steps: 10,
}
return wait.ExponentialBackoff(backoff, func() (bool, error) {
c.logger.Debugf("Waiting for job %v to become parameterized", spec.Job)
jobInfo, _ := c.GetJobInfo(spec)
isParameterized := false
if jobInfo != nil {
isParameterized = c.JobParameterized(jobInfo)
if isParameterized && jobInfo.LastBuild != nil {
c.logger.Debugf("Job %v is now parameterized, aborting the build", spec.Job)
err := c.Abort(getJobName(spec), jobInfo.LastBuild)
if err != nil {
c.logger.Infof("Couldn't abort build #%v for job %v: %v", jobInfo.LastBuild.Number, spec.Job, err)
}
}
}
// don't stop on (possibly) intermittent errors
return isParameterized, nil
})
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"EnsureBuildableJob",
"(",
"spec",
"*",
"prowapi",
".",
"ProwJobSpec",
")",
"error",
"{",
"var",
"jobInfo",
"*",
"JobInfo",
"\n",
"getJobInfoBackoff",
":=",
"wait",
".",
"Backoff",
"{",
"Duration",
":",
"time",
".",
"Duration",
"(",
"10",
")",
"*",
"time",
".",
"Second",
",",
"Factor",
":",
"1",
",",
"Jitter",
":",
"0",
",",
"Steps",
":",
"2",
",",
"}",
"\n",
"getJobErr",
":=",
"wait",
".",
"ExponentialBackoff",
"(",
"getJobInfoBackoff",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"jobErr",
"error",
"\n",
"jobInfo",
",",
"jobErr",
"=",
"c",
".",
"GetJobInfo",
"(",
"spec",
")",
"\n",
"if",
"jobErr",
"!=",
"nil",
"&&",
"!",
"strings",
".",
"Contains",
"(",
"strings",
".",
"ToLower",
"(",
"jobErr",
".",
"Error",
"(",
")",
")",
",",
"\"404 not found\"",
")",
"{",
"return",
"false",
",",
"jobErr",
"\n",
"}",
"\n",
"return",
"jobInfo",
"!=",
"nil",
",",
"nil",
"\n",
"}",
")",
"\n",
"if",
"getJobErr",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Job %v does not exist\"",
",",
"spec",
".",
"Job",
")",
"\n",
"}",
"\n",
"isParameterized",
":=",
"c",
".",
"JobParameterized",
"(",
"jobInfo",
")",
"\n",
"c",
".",
"logger",
".",
"Tracef",
"(",
"\"JobHasParameters: %v\"",
",",
"isParameterized",
")",
"\n",
"if",
"isParameterized",
"||",
"len",
"(",
"jobInfo",
".",
"Builds",
")",
">",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"buildErr",
":=",
"c",
".",
"LaunchBuild",
"(",
"spec",
",",
"nil",
")",
"\n",
"if",
"buildErr",
"!=",
"nil",
"{",
"return",
"buildErr",
"\n",
"}",
"\n",
"backoff",
":=",
"wait",
".",
"Backoff",
"{",
"Duration",
":",
"time",
".",
"Duration",
"(",
"5",
")",
"*",
"time",
".",
"Second",
",",
"Factor",
":",
"1",
",",
"Jitter",
":",
"1",
",",
"Steps",
":",
"10",
",",
"}",
"\n",
"return",
"wait",
".",
"ExponentialBackoff",
"(",
"backoff",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"c",
".",
"logger",
".",
"Debugf",
"(",
"\"Waiting for job %v to become parameterized\"",
",",
"spec",
".",
"Job",
")",
"\n",
"jobInfo",
",",
"_",
":=",
"c",
".",
"GetJobInfo",
"(",
"spec",
")",
"\n",
"isParameterized",
":=",
"false",
"\n",
"if",
"jobInfo",
"!=",
"nil",
"{",
"isParameterized",
"=",
"c",
".",
"JobParameterized",
"(",
"jobInfo",
")",
"\n",
"if",
"isParameterized",
"&&",
"jobInfo",
".",
"LastBuild",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Debugf",
"(",
"\"Job %v is now parameterized, aborting the build\"",
",",
"spec",
".",
"Job",
")",
"\n",
"err",
":=",
"c",
".",
"Abort",
"(",
"getJobName",
"(",
"spec",
")",
",",
"jobInfo",
".",
"LastBuild",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"logger",
".",
"Infof",
"(",
"\"Couldn't abort build #%v for job %v: %v\"",
",",
"jobInfo",
".",
"LastBuild",
".",
"Number",
",",
"spec",
".",
"Job",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"isParameterized",
",",
"nil",
"\n",
"}",
")",
"\n",
"}"
] |
// EnsureBuildableJob attempts to detect a job that hasn't yet ran and populated
// its parameters. If detected, it tries to run a build until the job parameters
// are processed, then it aborts the build.
|
[
"EnsureBuildableJob",
"attempts",
"to",
"detect",
"a",
"job",
"that",
"hasn",
"t",
"yet",
"ran",
"and",
"populated",
"its",
"parameters",
".",
"If",
"detected",
"it",
"tries",
"to",
"run",
"a",
"build",
"until",
"the",
"job",
"parameters",
"are",
"processed",
"then",
"it",
"aborts",
"the",
"build",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L496-L565
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
LaunchBuild
|
func (c *Client) LaunchBuild(spec *prowapi.ProwJobSpec, params url.Values) error {
var path string
if params != nil {
path = getBuildWithParametersPath(spec)
} else {
path = getBuildPath(spec)
}
c.logger.Debugf("getBuildPath/getBuildWithParametersPath: %s", path)
resp, err := c.request(http.MethodPost, path, params, true)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 201 {
return fmt.Errorf("response not 201: %s", resp.Status)
}
return nil
}
|
go
|
func (c *Client) LaunchBuild(spec *prowapi.ProwJobSpec, params url.Values) error {
var path string
if params != nil {
path = getBuildWithParametersPath(spec)
} else {
path = getBuildPath(spec)
}
c.logger.Debugf("getBuildPath/getBuildWithParametersPath: %s", path)
resp, err := c.request(http.MethodPost, path, params, true)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 201 {
return fmt.Errorf("response not 201: %s", resp.Status)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LaunchBuild",
"(",
"spec",
"*",
"prowapi",
".",
"ProwJobSpec",
",",
"params",
"url",
".",
"Values",
")",
"error",
"{",
"var",
"path",
"string",
"\n",
"if",
"params",
"!=",
"nil",
"{",
"path",
"=",
"getBuildWithParametersPath",
"(",
"spec",
")",
"\n",
"}",
"else",
"{",
"path",
"=",
"getBuildPath",
"(",
"spec",
")",
"\n",
"}",
"\n",
"c",
".",
"logger",
".",
"Debugf",
"(",
"\"getBuildPath/getBuildWithParametersPath: %s\"",
",",
"path",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"request",
"(",
"http",
".",
"MethodPost",
",",
"path",
",",
"params",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"201",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"response not 201: %s\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// LaunchBuild launches a regular or parameterized Jenkins build, depending on
// whether or not we have `params` to POST
|
[
"LaunchBuild",
"launches",
"a",
"regular",
"or",
"parameterized",
"Jenkins",
"build",
"depending",
"on",
"whether",
"or",
"not",
"we",
"have",
"params",
"to",
"POST"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L569-L593
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
Build
|
func (c *Client) Build(pj *prowapi.ProwJob, buildID string) error {
c.logger.WithFields(pjutil.ProwJobFields(pj)).Info("Build")
return c.BuildFromSpec(&pj.Spec, buildID, pj.ObjectMeta.Name)
}
|
go
|
func (c *Client) Build(pj *prowapi.ProwJob, buildID string) error {
c.logger.WithFields(pjutil.ProwJobFields(pj)).Info("Build")
return c.BuildFromSpec(&pj.Spec, buildID, pj.ObjectMeta.Name)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Build",
"(",
"pj",
"*",
"prowapi",
".",
"ProwJob",
",",
"buildID",
"string",
")",
"error",
"{",
"c",
".",
"logger",
".",
"WithFields",
"(",
"pjutil",
".",
"ProwJobFields",
"(",
"pj",
")",
")",
".",
"Info",
"(",
"\"Build\"",
")",
"\n",
"return",
"c",
".",
"BuildFromSpec",
"(",
"&",
"pj",
".",
"Spec",
",",
"buildID",
",",
"pj",
".",
"ObjectMeta",
".",
"Name",
")",
"\n",
"}"
] |
// Build triggers a Jenkins build for the provided ProwJob. The name of
// the ProwJob is going to be used as the Prow Job ID parameter that will
// help us track the build before it's scheduled by Jenkins.
|
[
"Build",
"triggers",
"a",
"Jenkins",
"build",
"for",
"the",
"provided",
"ProwJob",
".",
"The",
"name",
"of",
"the",
"ProwJob",
"is",
"going",
"to",
"be",
"used",
"as",
"the",
"Prow",
"Job",
"ID",
"parameter",
"that",
"will",
"help",
"us",
"track",
"the",
"build",
"before",
"it",
"s",
"scheduled",
"by",
"Jenkins",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L598-L601
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
BuildFromSpec
|
func (c *Client) BuildFromSpec(spec *prowapi.ProwJobSpec, buildID, prowJobID string) error {
if c.dryRun {
return nil
}
env, err := downwardapi.EnvForSpec(downwardapi.NewJobSpec(*spec, buildID, prowJobID))
if err != nil {
return err
}
params := url.Values{}
for key, value := range env {
params.Set(key, value)
}
if err := c.EnsureBuildableJob(spec); err != nil {
return fmt.Errorf("Job %v cannot be build: %v", spec.Job, err)
}
return c.LaunchBuild(spec, params)
}
|
go
|
func (c *Client) BuildFromSpec(spec *prowapi.ProwJobSpec, buildID, prowJobID string) error {
if c.dryRun {
return nil
}
env, err := downwardapi.EnvForSpec(downwardapi.NewJobSpec(*spec, buildID, prowJobID))
if err != nil {
return err
}
params := url.Values{}
for key, value := range env {
params.Set(key, value)
}
if err := c.EnsureBuildableJob(spec); err != nil {
return fmt.Errorf("Job %v cannot be build: %v", spec.Job, err)
}
return c.LaunchBuild(spec, params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"BuildFromSpec",
"(",
"spec",
"*",
"prowapi",
".",
"ProwJobSpec",
",",
"buildID",
",",
"prowJobID",
"string",
")",
"error",
"{",
"if",
"c",
".",
"dryRun",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"env",
",",
"err",
":=",
"downwardapi",
".",
"EnvForSpec",
"(",
"downwardapi",
".",
"NewJobSpec",
"(",
"*",
"spec",
",",
"buildID",
",",
"prowJobID",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"env",
"{",
"params",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"EnsureBuildableJob",
"(",
"spec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"Job %v cannot be build: %v\"",
",",
"spec",
".",
"Job",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"LaunchBuild",
"(",
"spec",
",",
"params",
")",
"\n",
"}"
] |
// BuildFromSpec triggers a Jenkins build for the provided ProwJobSpec.
// prowJobID helps us track the build before it's scheduled by Jenkins.
|
[
"BuildFromSpec",
"triggers",
"a",
"Jenkins",
"build",
"for",
"the",
"provided",
"ProwJobSpec",
".",
"prowJobID",
"helps",
"us",
"track",
"the",
"build",
"before",
"it",
"s",
"scheduled",
"by",
"Jenkins",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L605-L623
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
GetEnqueuedBuilds
|
func (c *Client) GetEnqueuedBuilds(jobs []BuildQueryParams) (map[string]Build, error) {
c.logger.Debug("GetEnqueuedBuilds")
data, err := c.Get("/queue/api/json?tree=items[task[name],actions[parameters[name,value]]]")
if err != nil {
return nil, fmt.Errorf("cannot list builds from the queue: %v", err)
}
page := struct {
QueuedBuilds []Build `json:"items"`
}{}
if err := json.Unmarshal(data, &page); err != nil {
return nil, fmt.Errorf("cannot unmarshal builds from the queue: %v", err)
}
jenkinsBuilds := make(map[string]Build)
for _, jb := range page.QueuedBuilds {
prowJobID := jb.ProwJobID()
// Ignore builds with missing buildID parameters.
if prowJobID == "" {
continue
}
// Ignore builds for jobs we didn't ask for.
var exists bool
for _, job := range jobs {
if prowJobID == job.ProwJobID {
exists = true
break
}
}
if !exists {
continue
}
jb.enqueued = true
jenkinsBuilds[prowJobID] = jb
}
return jenkinsBuilds, nil
}
|
go
|
func (c *Client) GetEnqueuedBuilds(jobs []BuildQueryParams) (map[string]Build, error) {
c.logger.Debug("GetEnqueuedBuilds")
data, err := c.Get("/queue/api/json?tree=items[task[name],actions[parameters[name,value]]]")
if err != nil {
return nil, fmt.Errorf("cannot list builds from the queue: %v", err)
}
page := struct {
QueuedBuilds []Build `json:"items"`
}{}
if err := json.Unmarshal(data, &page); err != nil {
return nil, fmt.Errorf("cannot unmarshal builds from the queue: %v", err)
}
jenkinsBuilds := make(map[string]Build)
for _, jb := range page.QueuedBuilds {
prowJobID := jb.ProwJobID()
// Ignore builds with missing buildID parameters.
if prowJobID == "" {
continue
}
// Ignore builds for jobs we didn't ask for.
var exists bool
for _, job := range jobs {
if prowJobID == job.ProwJobID {
exists = true
break
}
}
if !exists {
continue
}
jb.enqueued = true
jenkinsBuilds[prowJobID] = jb
}
return jenkinsBuilds, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"GetEnqueuedBuilds",
"(",
"jobs",
"[",
"]",
"BuildQueryParams",
")",
"(",
"map",
"[",
"string",
"]",
"Build",
",",
"error",
")",
"{",
"c",
".",
"logger",
".",
"Debug",
"(",
"\"GetEnqueuedBuilds\"",
")",
"\n",
"data",
",",
"err",
":=",
"c",
".",
"Get",
"(",
"\"/queue/api/json?tree=items[task[name],actions[parameters[name,value]]]\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"cannot list builds from the queue: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"page",
":=",
"struct",
"{",
"QueuedBuilds",
"[",
"]",
"Build",
"`json:\"items\"`",
"\n",
"}",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"page",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"cannot unmarshal builds from the queue: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"jenkinsBuilds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Build",
")",
"\n",
"for",
"_",
",",
"jb",
":=",
"range",
"page",
".",
"QueuedBuilds",
"{",
"prowJobID",
":=",
"jb",
".",
"ProwJobID",
"(",
")",
"\n",
"if",
"prowJobID",
"==",
"\"\"",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"exists",
"bool",
"\n",
"for",
"_",
",",
"job",
":=",
"range",
"jobs",
"{",
"if",
"prowJobID",
"==",
"job",
".",
"ProwJobID",
"{",
"exists",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"exists",
"{",
"continue",
"\n",
"}",
"\n",
"jb",
".",
"enqueued",
"=",
"true",
"\n",
"jenkinsBuilds",
"[",
"prowJobID",
"]",
"=",
"jb",
"\n",
"}",
"\n",
"return",
"jenkinsBuilds",
",",
"nil",
"\n",
"}"
] |
// GetEnqueuedBuilds lists all enqueued builds for the provided jobs.
|
[
"GetEnqueuedBuilds",
"lists",
"all",
"enqueued",
"builds",
"for",
"the",
"provided",
"jobs",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L674-L709
|
test
|
kubernetes/test-infra
|
prow/jenkins/jenkins.go
|
Abort
|
func (c *Client) Abort(job string, build *Build) error {
c.logger.Debugf("Abort(%v %v)", job, build.Number)
if c.dryRun {
return nil
}
resp, err := c.request(http.MethodPost, fmt.Sprintf("/job/%s/%d/stop", job, build.Number), nil, false)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("response not 2XX: %s", resp.Status)
}
return nil
}
|
go
|
func (c *Client) Abort(job string, build *Build) error {
c.logger.Debugf("Abort(%v %v)", job, build.Number)
if c.dryRun {
return nil
}
resp, err := c.request(http.MethodPost, fmt.Sprintf("/job/%s/%d/stop", job, build.Number), nil, false)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("response not 2XX: %s", resp.Status)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Abort",
"(",
"job",
"string",
",",
"build",
"*",
"Build",
")",
"error",
"{",
"c",
".",
"logger",
".",
"Debugf",
"(",
"\"Abort(%v %v)\"",
",",
"job",
",",
"build",
".",
"Number",
")",
"\n",
"if",
"c",
".",
"dryRun",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"request",
"(",
"http",
".",
"MethodPost",
",",
"fmt",
".",
"Sprintf",
"(",
"\"/job/%s/%d/stop\"",
",",
"job",
",",
"build",
".",
"Number",
")",
",",
"nil",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"<",
"200",
"||",
"resp",
".",
"StatusCode",
">=",
"300",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"response not 2XX: %s\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Abort aborts the provided Jenkins build for job.
|
[
"Abort",
"aborts",
"the",
"provided",
"Jenkins",
"build",
"for",
"job",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/jenkins.go#L745-L759
|
test
|
kubernetes/test-infra
|
prow/pjutil/tot.go
|
PresubmitToJobSpec
|
func PresubmitToJobSpec(pre config.Presubmit) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PresubmitJob,
Job: pre.Name,
}
}
|
go
|
func PresubmitToJobSpec(pre config.Presubmit) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PresubmitJob,
Job: pre.Name,
}
}
|
[
"func",
"PresubmitToJobSpec",
"(",
"pre",
"config",
".",
"Presubmit",
")",
"*",
"downwardapi",
".",
"JobSpec",
"{",
"return",
"&",
"downwardapi",
".",
"JobSpec",
"{",
"Type",
":",
"prowapi",
".",
"PresubmitJob",
",",
"Job",
":",
"pre",
".",
"Name",
",",
"}",
"\n",
"}"
] |
// PresubmitToJobSpec generates a downwardapi.JobSpec out of a Presubmit.
// Useful for figuring out GCS paths when parsing jobs out
// of a prow config.
|
[
"PresubmitToJobSpec",
"generates",
"a",
"downwardapi",
".",
"JobSpec",
"out",
"of",
"a",
"Presubmit",
".",
"Useful",
"for",
"figuring",
"out",
"GCS",
"paths",
"when",
"parsing",
"jobs",
"out",
"of",
"a",
"prow",
"config",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pjutil/tot.go#L51-L56
|
test
|
kubernetes/test-infra
|
prow/pjutil/tot.go
|
PostsubmitToJobSpec
|
func PostsubmitToJobSpec(post config.Postsubmit) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PostsubmitJob,
Job: post.Name,
}
}
|
go
|
func PostsubmitToJobSpec(post config.Postsubmit) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PostsubmitJob,
Job: post.Name,
}
}
|
[
"func",
"PostsubmitToJobSpec",
"(",
"post",
"config",
".",
"Postsubmit",
")",
"*",
"downwardapi",
".",
"JobSpec",
"{",
"return",
"&",
"downwardapi",
".",
"JobSpec",
"{",
"Type",
":",
"prowapi",
".",
"PostsubmitJob",
",",
"Job",
":",
"post",
".",
"Name",
",",
"}",
"\n",
"}"
] |
// PostsubmitToJobSpec generates a downwardapi.JobSpec out of a Postsubmit.
// Useful for figuring out GCS paths when parsing jobs out
// of a prow config.
|
[
"PostsubmitToJobSpec",
"generates",
"a",
"downwardapi",
".",
"JobSpec",
"out",
"of",
"a",
"Postsubmit",
".",
"Useful",
"for",
"figuring",
"out",
"GCS",
"paths",
"when",
"parsing",
"jobs",
"out",
"of",
"a",
"prow",
"config",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pjutil/tot.go#L61-L66
|
test
|
kubernetes/test-infra
|
prow/pjutil/tot.go
|
PeriodicToJobSpec
|
func PeriodicToJobSpec(periodic config.Periodic) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PeriodicJob,
Job: periodic.Name,
}
}
|
go
|
func PeriodicToJobSpec(periodic config.Periodic) *downwardapi.JobSpec {
return &downwardapi.JobSpec{
Type: prowapi.PeriodicJob,
Job: periodic.Name,
}
}
|
[
"func",
"PeriodicToJobSpec",
"(",
"periodic",
"config",
".",
"Periodic",
")",
"*",
"downwardapi",
".",
"JobSpec",
"{",
"return",
"&",
"downwardapi",
".",
"JobSpec",
"{",
"Type",
":",
"prowapi",
".",
"PeriodicJob",
",",
"Job",
":",
"periodic",
".",
"Name",
",",
"}",
"\n",
"}"
] |
// PeriodicToJobSpec generates a downwardapi.JobSpec out of a Periodic.
// Useful for figuring out GCS paths when parsing jobs out
// of a prow config.
|
[
"PeriodicToJobSpec",
"generates",
"a",
"downwardapi",
".",
"JobSpec",
"out",
"of",
"a",
"Periodic",
".",
"Useful",
"for",
"figuring",
"out",
"GCS",
"paths",
"when",
"parsing",
"jobs",
"out",
"of",
"a",
"prow",
"config",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pjutil/tot.go#L71-L76
|
test
|
kubernetes/test-infra
|
prow/pjutil/tot.go
|
GetBuildID
|
func GetBuildID(name, totURL string) (string, error) {
if totURL == "" {
return node.Generate().String(), nil
}
var err error
url, err := url.Parse(totURL)
if err != nil {
return "", fmt.Errorf("invalid tot url: %v", err)
}
url.Path = path.Join(url.Path, "vend", name)
sleepDuration := 100 * time.Millisecond
for retries := 0; retries < 10; retries++ {
if retries > 0 {
sleep(sleepDuration)
sleepDuration = sleepDuration * 2
}
var resp *http.Response
resp, err = http.Get(url.String())
if err != nil {
continue
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("got unexpected response from tot: %v", resp.Status)
continue
}
var buf []byte
buf, err = ioutil.ReadAll(resp.Body)
if err == nil {
return string(buf), nil
}
return "", err
}
return "", err
}
|
go
|
func GetBuildID(name, totURL string) (string, error) {
if totURL == "" {
return node.Generate().String(), nil
}
var err error
url, err := url.Parse(totURL)
if err != nil {
return "", fmt.Errorf("invalid tot url: %v", err)
}
url.Path = path.Join(url.Path, "vend", name)
sleepDuration := 100 * time.Millisecond
for retries := 0; retries < 10; retries++ {
if retries > 0 {
sleep(sleepDuration)
sleepDuration = sleepDuration * 2
}
var resp *http.Response
resp, err = http.Get(url.String())
if err != nil {
continue
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("got unexpected response from tot: %v", resp.Status)
continue
}
var buf []byte
buf, err = ioutil.ReadAll(resp.Body)
if err == nil {
return string(buf), nil
}
return "", err
}
return "", err
}
|
[
"func",
"GetBuildID",
"(",
"name",
",",
"totURL",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"totURL",
"==",
"\"\"",
"{",
"return",
"node",
".",
"Generate",
"(",
")",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"url",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"totURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid tot url: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"url",
".",
"Path",
"=",
"path",
".",
"Join",
"(",
"url",
".",
"Path",
",",
"\"vend\"",
",",
"name",
")",
"\n",
"sleepDuration",
":=",
"100",
"*",
"time",
".",
"Millisecond",
"\n",
"for",
"retries",
":=",
"0",
";",
"retries",
"<",
"10",
";",
"retries",
"++",
"{",
"if",
"retries",
">",
"0",
"{",
"sleep",
"(",
"sleepDuration",
")",
"\n",
"sleepDuration",
"=",
"sleepDuration",
"*",
"2",
"\n",
"}",
"\n",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"resp",
",",
"err",
"=",
"http",
".",
"Get",
"(",
"url",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"200",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"got unexpected response from tot: %v\"",
",",
"resp",
".",
"Status",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"var",
"buf",
"[",
"]",
"byte",
"\n",
"buf",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"string",
"(",
"buf",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"\"\"",
",",
"err",
"\n",
"}"
] |
// GetBuildID calls out to `tot` in order
// to vend build identifier for the job
|
[
"GetBuildID",
"calls",
"out",
"to",
"tot",
"in",
"order",
"to",
"vend",
"build",
"identifier",
"for",
"the",
"job"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pjutil/tot.go#L80-L114
|
test
|
kubernetes/test-infra
|
robots/coverage/downloader/downloader.go
|
listGcsObjects
|
func listGcsObjects(ctx context.Context, client *storage.Client, bucketName, prefix, delim string) (
[]string, error) {
var objects []string
it := client.Bucket(bucketName).Objects(ctx, &storage.Query{
Prefix: prefix,
Delimiter: delim,
})
for {
attrs, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
return objects, fmt.Errorf("error iterating: %v", err)
}
if attrs.Prefix != "" {
objects = append(objects, path.Base(attrs.Prefix))
}
}
logrus.Info("end of listGcsObjects(...)")
return objects, nil
}
|
go
|
func listGcsObjects(ctx context.Context, client *storage.Client, bucketName, prefix, delim string) (
[]string, error) {
var objects []string
it := client.Bucket(bucketName).Objects(ctx, &storage.Query{
Prefix: prefix,
Delimiter: delim,
})
for {
attrs, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
return objects, fmt.Errorf("error iterating: %v", err)
}
if attrs.Prefix != "" {
objects = append(objects, path.Base(attrs.Prefix))
}
}
logrus.Info("end of listGcsObjects(...)")
return objects, nil
}
|
[
"func",
"listGcsObjects",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"storage",
".",
"Client",
",",
"bucketName",
",",
"prefix",
",",
"delim",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"objects",
"[",
"]",
"string",
"\n",
"it",
":=",
"client",
".",
"Bucket",
"(",
"bucketName",
")",
".",
"Objects",
"(",
"ctx",
",",
"&",
"storage",
".",
"Query",
"{",
"Prefix",
":",
"prefix",
",",
"Delimiter",
":",
"delim",
",",
"}",
")",
"\n",
"for",
"{",
"attrs",
",",
"err",
":=",
"it",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"iterator",
".",
"Done",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"objects",
",",
"fmt",
".",
"Errorf",
"(",
"\"error iterating: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"attrs",
".",
"Prefix",
"!=",
"\"\"",
"{",
"objects",
"=",
"append",
"(",
"objects",
",",
"path",
".",
"Base",
"(",
"attrs",
".",
"Prefix",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"logrus",
".",
"Info",
"(",
"\"end of listGcsObjects(...)\"",
")",
"\n",
"return",
"objects",
",",
"nil",
"\n",
"}"
] |
//listGcsObjects get the slice of gcs objects under a given path
|
[
"listGcsObjects",
"get",
"the",
"slice",
"of",
"gcs",
"objects",
"under",
"a",
"given",
"path"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/coverage/downloader/downloader.go#L41-L65
|
test
|
kubernetes/test-infra
|
robots/coverage/downloader/downloader.go
|
FindBaseProfile
|
func FindBaseProfile(ctx context.Context, client *storage.Client, bucket, prowJobName, artifactsDirName,
covProfileName string) ([]byte, error) {
dirOfJob := path.Join("logs", prowJobName)
strBuilds, err := listGcsObjects(ctx, client, bucket, dirOfJob+"/", "/")
if err != nil {
return nil, fmt.Errorf("error listing gcs objects: %v", err)
}
builds := sortBuilds(strBuilds)
profilePath := ""
for _, build := range builds {
buildDirPath := path.Join(dirOfJob, strconv.Itoa(build))
dirOfStatusJSON := path.Join(buildDirPath, statusJSON)
statusText, err := readGcsObject(ctx, client, bucket, dirOfStatusJSON)
if err != nil {
logrus.Infof("Cannot read finished.json (%s) in bucket '%s'", dirOfStatusJSON, bucket)
} else if isBuildSucceeded(statusText) {
artifactsDirPath := path.Join(buildDirPath, artifactsDirName)
profilePath = path.Join(artifactsDirPath, covProfileName)
break
}
}
if profilePath == "" {
return nil, fmt.Errorf("no healthy build found for job '%s' in bucket '%s'; total # builds = %v", dirOfJob, bucket, len(builds))
}
return readGcsObject(ctx, client, bucket, profilePath)
}
|
go
|
func FindBaseProfile(ctx context.Context, client *storage.Client, bucket, prowJobName, artifactsDirName,
covProfileName string) ([]byte, error) {
dirOfJob := path.Join("logs", prowJobName)
strBuilds, err := listGcsObjects(ctx, client, bucket, dirOfJob+"/", "/")
if err != nil {
return nil, fmt.Errorf("error listing gcs objects: %v", err)
}
builds := sortBuilds(strBuilds)
profilePath := ""
for _, build := range builds {
buildDirPath := path.Join(dirOfJob, strconv.Itoa(build))
dirOfStatusJSON := path.Join(buildDirPath, statusJSON)
statusText, err := readGcsObject(ctx, client, bucket, dirOfStatusJSON)
if err != nil {
logrus.Infof("Cannot read finished.json (%s) in bucket '%s'", dirOfStatusJSON, bucket)
} else if isBuildSucceeded(statusText) {
artifactsDirPath := path.Join(buildDirPath, artifactsDirName)
profilePath = path.Join(artifactsDirPath, covProfileName)
break
}
}
if profilePath == "" {
return nil, fmt.Errorf("no healthy build found for job '%s' in bucket '%s'; total # builds = %v", dirOfJob, bucket, len(builds))
}
return readGcsObject(ctx, client, bucket, profilePath)
}
|
[
"func",
"FindBaseProfile",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"storage",
".",
"Client",
",",
"bucket",
",",
"prowJobName",
",",
"artifactsDirName",
",",
"covProfileName",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"dirOfJob",
":=",
"path",
".",
"Join",
"(",
"\"logs\"",
",",
"prowJobName",
")",
"\n",
"strBuilds",
",",
"err",
":=",
"listGcsObjects",
"(",
"ctx",
",",
"client",
",",
"bucket",
",",
"dirOfJob",
"+",
"\"/\"",
",",
"\"/\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"error listing gcs objects: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"builds",
":=",
"sortBuilds",
"(",
"strBuilds",
")",
"\n",
"profilePath",
":=",
"\"\"",
"\n",
"for",
"_",
",",
"build",
":=",
"range",
"builds",
"{",
"buildDirPath",
":=",
"path",
".",
"Join",
"(",
"dirOfJob",
",",
"strconv",
".",
"Itoa",
"(",
"build",
")",
")",
"\n",
"dirOfStatusJSON",
":=",
"path",
".",
"Join",
"(",
"buildDirPath",
",",
"statusJSON",
")",
"\n",
"statusText",
",",
"err",
":=",
"readGcsObject",
"(",
"ctx",
",",
"client",
",",
"bucket",
",",
"dirOfStatusJSON",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Infof",
"(",
"\"Cannot read finished.json (%s) in bucket '%s'\"",
",",
"dirOfStatusJSON",
",",
"bucket",
")",
"\n",
"}",
"else",
"if",
"isBuildSucceeded",
"(",
"statusText",
")",
"{",
"artifactsDirPath",
":=",
"path",
".",
"Join",
"(",
"buildDirPath",
",",
"artifactsDirName",
")",
"\n",
"profilePath",
"=",
"path",
".",
"Join",
"(",
"artifactsDirPath",
",",
"covProfileName",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"profilePath",
"==",
"\"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"no healthy build found for job '%s' in bucket '%s'; total # builds = %v\"",
",",
"dirOfJob",
",",
"bucket",
",",
"len",
"(",
"builds",
")",
")",
"\n",
"}",
"\n",
"return",
"readGcsObject",
"(",
"ctx",
",",
"client",
",",
"bucket",
",",
"profilePath",
")",
"\n",
"}"
] |
// FindBaseProfile finds the coverage profile file from the latest healthy build
// stored in given gcs directory
|
[
"FindBaseProfile",
"finds",
"the",
"coverage",
"profile",
"file",
"from",
"the",
"latest",
"healthy",
"build",
"stored",
"in",
"given",
"gcs",
"directory"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/coverage/downloader/downloader.go#L79-L108
|
test
|
kubernetes/test-infra
|
robots/coverage/downloader/downloader.go
|
sortBuilds
|
func sortBuilds(strBuilds []string) []int {
var res []int
for _, buildStr := range strBuilds {
num, err := strconv.Atoi(buildStr)
if err != nil {
logrus.Infof("Non-int build number found: '%s'", buildStr)
} else {
res = append(res, num)
}
}
sort.Sort(sort.Reverse(sort.IntSlice(res)))
return res
}
|
go
|
func sortBuilds(strBuilds []string) []int {
var res []int
for _, buildStr := range strBuilds {
num, err := strconv.Atoi(buildStr)
if err != nil {
logrus.Infof("Non-int build number found: '%s'", buildStr)
} else {
res = append(res, num)
}
}
sort.Sort(sort.Reverse(sort.IntSlice(res)))
return res
}
|
[
"func",
"sortBuilds",
"(",
"strBuilds",
"[",
"]",
"string",
")",
"[",
"]",
"int",
"{",
"var",
"res",
"[",
"]",
"int",
"\n",
"for",
"_",
",",
"buildStr",
":=",
"range",
"strBuilds",
"{",
"num",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"buildStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Infof",
"(",
"\"Non-int build number found: '%s'\"",
",",
"buildStr",
")",
"\n",
"}",
"else",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"num",
")",
"\n",
"}",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"sort",
".",
"Reverse",
"(",
"sort",
".",
"IntSlice",
"(",
"res",
")",
")",
")",
"\n",
"return",
"res",
"\n",
"}"
] |
// sortBuilds converts all build from str to int and sorts all builds in descending order and
// returns the sorted slice
|
[
"sortBuilds",
"converts",
"all",
"build",
"from",
"str",
"to",
"int",
"and",
"sorts",
"all",
"builds",
"in",
"descending",
"order",
"and",
"returns",
"the",
"sorted",
"slice"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/coverage/downloader/downloader.go#L112-L124
|
test
|
kubernetes/test-infra
|
maintenance/aws-janitor/regions/regions.go
|
GetAll
|
func GetAll(sess *session.Session) ([]string, error) {
var regions []string
svc := ec2.New(sess, &aws.Config{Region: aws.String(Default)})
resp, err := svc.DescribeRegions(nil)
if err != nil {
return nil, err
}
for _, region := range resp.Regions {
regions = append(regions, *region.RegionName)
}
return regions, nil
}
|
go
|
func GetAll(sess *session.Session) ([]string, error) {
var regions []string
svc := ec2.New(sess, &aws.Config{Region: aws.String(Default)})
resp, err := svc.DescribeRegions(nil)
if err != nil {
return nil, err
}
for _, region := range resp.Regions {
regions = append(regions, *region.RegionName)
}
return regions, nil
}
|
[
"func",
"GetAll",
"(",
"sess",
"*",
"session",
".",
"Session",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"regions",
"[",
"]",
"string",
"\n",
"svc",
":=",
"ec2",
".",
"New",
"(",
"sess",
",",
"&",
"aws",
".",
"Config",
"{",
"Region",
":",
"aws",
".",
"String",
"(",
"Default",
")",
"}",
")",
"\n",
"resp",
",",
"err",
":=",
"svc",
".",
"DescribeRegions",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"region",
":=",
"range",
"resp",
".",
"Regions",
"{",
"regions",
"=",
"append",
"(",
"regions",
",",
"*",
"region",
".",
"RegionName",
")",
"\n",
"}",
"\n",
"return",
"regions",
",",
"nil",
"\n",
"}"
] |
// GetAll retrieves all regions from the AWS API
|
[
"GetAll",
"retrieves",
"all",
"regions",
"from",
"the",
"AWS",
"API"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/maintenance/aws-janitor/regions/regions.go#L37-L48
|
test
|
kubernetes/test-infra
|
prow/commentpruner/commentpruner.go
|
NewEventClient
|
func NewEventClient(ghc githubClient, log *logrus.Entry, org, repo string, number int) *EventClient {
return &EventClient{
org: org,
repo: repo,
number: number,
ghc: ghc,
log: log,
}
}
|
go
|
func NewEventClient(ghc githubClient, log *logrus.Entry, org, repo string, number int) *EventClient {
return &EventClient{
org: org,
repo: repo,
number: number,
ghc: ghc,
log: log,
}
}
|
[
"func",
"NewEventClient",
"(",
"ghc",
"githubClient",
",",
"log",
"*",
"logrus",
".",
"Entry",
",",
"org",
",",
"repo",
"string",
",",
"number",
"int",
")",
"*",
"EventClient",
"{",
"return",
"&",
"EventClient",
"{",
"org",
":",
"org",
",",
"repo",
":",
"repo",
",",
"number",
":",
"number",
",",
"ghc",
":",
"ghc",
",",
"log",
":",
"log",
",",
"}",
"\n",
"}"
] |
// NewEventClient creates an EventClient struct. This should be used once per webhook event.
|
[
"NewEventClient",
"creates",
"an",
"EventClient",
"struct",
".",
"This",
"should",
"be",
"used",
"once",
"per",
"webhook",
"event",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/commentpruner/commentpruner.go#L54-L63
|
test
|
kubernetes/test-infra
|
prow/commentpruner/commentpruner.go
|
PruneComments
|
func (c *EventClient) PruneComments(shouldPrune func(github.IssueComment) bool) {
c.once.Do(func() {
botName, err := c.ghc.BotName()
if err != nil {
c.log.WithError(err).Error("failed to get the bot's name. Pruning will consider all comments.")
}
comments, err := c.ghc.ListIssueComments(c.org, c.repo, c.number)
if err != nil {
c.log.WithError(err).Errorf("failed to list comments for %s/%s#%d", c.org, c.repo, c.number)
}
if botName != "" {
for _, comment := range comments {
if comment.User.Login == botName {
c.comments = append(c.comments, comment)
}
}
}
})
c.lock.Lock()
defer c.lock.Unlock()
var remaining []github.IssueComment
for _, comment := range c.comments {
removed := false
if shouldPrune(comment) {
if err := c.ghc.DeleteComment(c.org, c.repo, comment.ID); err != nil {
c.log.WithError(err).Errorf("failed to delete stale comment with ID '%d'", comment.ID)
} else {
removed = true
}
}
if !removed {
remaining = append(remaining, comment)
}
}
c.comments = remaining
}
|
go
|
func (c *EventClient) PruneComments(shouldPrune func(github.IssueComment) bool) {
c.once.Do(func() {
botName, err := c.ghc.BotName()
if err != nil {
c.log.WithError(err).Error("failed to get the bot's name. Pruning will consider all comments.")
}
comments, err := c.ghc.ListIssueComments(c.org, c.repo, c.number)
if err != nil {
c.log.WithError(err).Errorf("failed to list comments for %s/%s#%d", c.org, c.repo, c.number)
}
if botName != "" {
for _, comment := range comments {
if comment.User.Login == botName {
c.comments = append(c.comments, comment)
}
}
}
})
c.lock.Lock()
defer c.lock.Unlock()
var remaining []github.IssueComment
for _, comment := range c.comments {
removed := false
if shouldPrune(comment) {
if err := c.ghc.DeleteComment(c.org, c.repo, comment.ID); err != nil {
c.log.WithError(err).Errorf("failed to delete stale comment with ID '%d'", comment.ID)
} else {
removed = true
}
}
if !removed {
remaining = append(remaining, comment)
}
}
c.comments = remaining
}
|
[
"func",
"(",
"c",
"*",
"EventClient",
")",
"PruneComments",
"(",
"shouldPrune",
"func",
"(",
"github",
".",
"IssueComment",
")",
"bool",
")",
"{",
"c",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"botName",
",",
"err",
":=",
"c",
".",
"ghc",
".",
"BotName",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"failed to get the bot's name. Pruning will consider all comments.\"",
")",
"\n",
"}",
"\n",
"comments",
",",
"err",
":=",
"c",
".",
"ghc",
".",
"ListIssueComments",
"(",
"c",
".",
"org",
",",
"c",
".",
"repo",
",",
"c",
".",
"number",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"failed to list comments for %s/%s#%d\"",
",",
"c",
".",
"org",
",",
"c",
".",
"repo",
",",
"c",
".",
"number",
")",
"\n",
"}",
"\n",
"if",
"botName",
"!=",
"\"\"",
"{",
"for",
"_",
",",
"comment",
":=",
"range",
"comments",
"{",
"if",
"comment",
".",
"User",
".",
"Login",
"==",
"botName",
"{",
"c",
".",
"comments",
"=",
"append",
"(",
"c",
".",
"comments",
",",
"comment",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"var",
"remaining",
"[",
"]",
"github",
".",
"IssueComment",
"\n",
"for",
"_",
",",
"comment",
":=",
"range",
"c",
".",
"comments",
"{",
"removed",
":=",
"false",
"\n",
"if",
"shouldPrune",
"(",
"comment",
")",
"{",
"if",
"err",
":=",
"c",
".",
"ghc",
".",
"DeleteComment",
"(",
"c",
".",
"org",
",",
"c",
".",
"repo",
",",
"comment",
".",
"ID",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"failed to delete stale comment with ID '%d'\"",
",",
"comment",
".",
"ID",
")",
"\n",
"}",
"else",
"{",
"removed",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"removed",
"{",
"remaining",
"=",
"append",
"(",
"remaining",
",",
"comment",
")",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"comments",
"=",
"remaining",
"\n",
"}"
] |
// PruneComments fetches issue comments if they have not yet been fetched for this webhook event
// and then deletes any bot comments indicated by the func 'shouldPrune'.
|
[
"PruneComments",
"fetches",
"issue",
"comments",
"if",
"they",
"have",
"not",
"yet",
"been",
"fetched",
"for",
"this",
"webhook",
"event",
"and",
"then",
"deletes",
"any",
"bot",
"comments",
"indicated",
"by",
"the",
"func",
"shouldPrune",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/commentpruner/commentpruner.go#L67-L104
|
test
|
kubernetes/test-infra
|
prow/plugins/respond.go
|
FormatResponse
|
func FormatResponse(to, message, reason string) string {
format := `@%s: %s
<details>
%s
%s
</details>`
return fmt.Sprintf(format, to, message, reason, AboutThisBotWithoutCommands)
}
|
go
|
func FormatResponse(to, message, reason string) string {
format := `@%s: %s
<details>
%s
%s
</details>`
return fmt.Sprintf(format, to, message, reason, AboutThisBotWithoutCommands)
}
|
[
"func",
"FormatResponse",
"(",
"to",
",",
"message",
",",
"reason",
"string",
")",
"string",
"{",
"format",
":=",
"`@%s: %s<details>%s%s</details>`",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"to",
",",
"message",
",",
"reason",
",",
"AboutThisBotWithoutCommands",
")",
"\n",
"}"
] |
// FormatResponse nicely formats a response to a generic reason.
|
[
"FormatResponse",
"nicely",
"formats",
"a",
"response",
"to",
"a",
"generic",
"reason",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/respond.go#L36-L47
|
test
|
kubernetes/test-infra
|
prow/plugins/respond.go
|
FormatSimpleResponse
|
func FormatSimpleResponse(to, message string) string {
format := `@%s: %s
<details>
%s
</details>`
return fmt.Sprintf(format, to, message, AboutThisBotWithoutCommands)
}
|
go
|
func FormatSimpleResponse(to, message string) string {
format := `@%s: %s
<details>
%s
</details>`
return fmt.Sprintf(format, to, message, AboutThisBotWithoutCommands)
}
|
[
"func",
"FormatSimpleResponse",
"(",
"to",
",",
"message",
"string",
")",
"string",
"{",
"format",
":=",
"`@%s: %s<details>%s</details>`",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"to",
",",
"message",
",",
"AboutThisBotWithoutCommands",
")",
"\n",
"}"
] |
// FormatSimpleResponse formats a response that does not warrant additional explanation in the
// details section.
|
[
"FormatSimpleResponse",
"formats",
"a",
"response",
"that",
"does",
"not",
"warrant",
"additional",
"explanation",
"in",
"the",
"details",
"section",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/respond.go#L51-L60
|
test
|
kubernetes/test-infra
|
prow/plugins/respond.go
|
FormatICResponse
|
func FormatICResponse(ic github.IssueComment, s string) string {
return FormatResponseRaw(ic.Body, ic.HTMLURL, ic.User.Login, s)
}
|
go
|
func FormatICResponse(ic github.IssueComment, s string) string {
return FormatResponseRaw(ic.Body, ic.HTMLURL, ic.User.Login, s)
}
|
[
"func",
"FormatICResponse",
"(",
"ic",
"github",
".",
"IssueComment",
",",
"s",
"string",
")",
"string",
"{",
"return",
"FormatResponseRaw",
"(",
"ic",
".",
"Body",
",",
"ic",
".",
"HTMLURL",
",",
"ic",
".",
"User",
".",
"Login",
",",
"s",
")",
"\n",
"}"
] |
// FormatICResponse nicely formats a response to an issue comment.
|
[
"FormatICResponse",
"nicely",
"formats",
"a",
"response",
"to",
"an",
"issue",
"comment",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/respond.go#L63-L65
|
test
|
kubernetes/test-infra
|
prow/plugins/respond.go
|
FormatResponseRaw
|
func FormatResponseRaw(body, bodyURL, login, reply string) string {
format := `In response to [this](%s):
%s
`
// Quote the user's comment by prepending ">" to each line.
var quoted []string
for _, l := range strings.Split(body, "\n") {
quoted = append(quoted, ">"+l)
}
return FormatResponse(login, reply, fmt.Sprintf(format, bodyURL, strings.Join(quoted, "\n")))
}
|
go
|
func FormatResponseRaw(body, bodyURL, login, reply string) string {
format := `In response to [this](%s):
%s
`
// Quote the user's comment by prepending ">" to each line.
var quoted []string
for _, l := range strings.Split(body, "\n") {
quoted = append(quoted, ">"+l)
}
return FormatResponse(login, reply, fmt.Sprintf(format, bodyURL, strings.Join(quoted, "\n")))
}
|
[
"func",
"FormatResponseRaw",
"(",
"body",
",",
"bodyURL",
",",
"login",
",",
"reply",
"string",
")",
"string",
"{",
"format",
":=",
"`In response to [this](%s):%s`",
"\n",
"var",
"quoted",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"strings",
".",
"Split",
"(",
"body",
",",
"\"\\n\"",
")",
"\\n",
"\n",
"{",
"quoted",
"=",
"append",
"(",
"quoted",
",",
"\">\"",
"+",
"l",
")",
"\n",
"}",
"\n",
"}"
] |
// FormatResponseRaw nicely formats a response for one does not have an issue comment
|
[
"FormatResponseRaw",
"nicely",
"formats",
"a",
"response",
"for",
"one",
"does",
"not",
"have",
"an",
"issue",
"comment"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/respond.go#L68-L79
|
test
|
kubernetes/test-infra
|
prow/gcsupload/options.go
|
Validate
|
func (o *Options) Validate() error {
if o.gcsPath.String() != "" {
o.Bucket = o.gcsPath.Bucket()
o.PathPrefix = o.gcsPath.Object()
}
if !o.DryRun {
if o.Bucket == "" {
return errors.New("GCS upload was requested no GCS bucket was provided")
}
if o.GcsCredentialsFile == "" {
return errors.New("GCS upload was requested but no GCS credentials file was provided")
}
}
return o.GCSConfiguration.Validate()
}
|
go
|
func (o *Options) Validate() error {
if o.gcsPath.String() != "" {
o.Bucket = o.gcsPath.Bucket()
o.PathPrefix = o.gcsPath.Object()
}
if !o.DryRun {
if o.Bucket == "" {
return errors.New("GCS upload was requested no GCS bucket was provided")
}
if o.GcsCredentialsFile == "" {
return errors.New("GCS upload was requested but no GCS credentials file was provided")
}
}
return o.GCSConfiguration.Validate()
}
|
[
"func",
"(",
"o",
"*",
"Options",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"o",
".",
"gcsPath",
".",
"String",
"(",
")",
"!=",
"\"\"",
"{",
"o",
".",
"Bucket",
"=",
"o",
".",
"gcsPath",
".",
"Bucket",
"(",
")",
"\n",
"o",
".",
"PathPrefix",
"=",
"o",
".",
"gcsPath",
".",
"Object",
"(",
")",
"\n",
"}",
"\n",
"if",
"!",
"o",
".",
"DryRun",
"{",
"if",
"o",
".",
"Bucket",
"==",
"\"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"GCS upload was requested no GCS bucket was provided\"",
")",
"\n",
"}",
"\n",
"if",
"o",
".",
"GcsCredentialsFile",
"==",
"\"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"GCS upload was requested but no GCS credentials file was provided\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"o",
".",
"GCSConfiguration",
".",
"Validate",
"(",
")",
"\n",
"}"
] |
// Validate ensures that the set of options are
// self-consistent and valid.
|
[
"Validate",
"ensures",
"that",
"the",
"set",
"of",
"options",
"are",
"self",
"-",
"consistent",
"and",
"valid",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/gcsupload/options.go#L59-L76
|
test
|
kubernetes/test-infra
|
prow/gcsupload/options.go
|
Encode
|
func Encode(options Options) (string, error) {
encoded, err := json.Marshal(options)
return string(encoded), err
}
|
go
|
func Encode(options Options) (string, error) {
encoded, err := json.Marshal(options)
return string(encoded), err
}
|
[
"func",
"Encode",
"(",
"options",
"Options",
")",
"(",
"string",
",",
"error",
")",
"{",
"encoded",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"options",
")",
"\n",
"return",
"string",
"(",
"encoded",
")",
",",
"err",
"\n",
"}"
] |
// Encode will encode the set of options in the format that
// is expected for the configuration environment variable.
|
[
"Encode",
"will",
"encode",
"the",
"set",
"of",
"options",
"in",
"the",
"format",
"that",
"is",
"expected",
"for",
"the",
"configuration",
"environment",
"variable",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/gcsupload/options.go#L117-L120
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterIssueHandler
|
func RegisterIssueHandler(name string, fn IssueHandler, help HelpProvider) {
pluginHelp[name] = help
issueHandlers[name] = fn
}
|
go
|
func RegisterIssueHandler(name string, fn IssueHandler, help HelpProvider) {
pluginHelp[name] = help
issueHandlers[name] = fn
}
|
[
"func",
"RegisterIssueHandler",
"(",
"name",
"string",
",",
"fn",
"IssueHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"issueHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterIssueHandler registers a plugin's github.IssueEvent handler.
|
[
"RegisterIssueHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"IssueEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L65-L68
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterIssueCommentHandler
|
func RegisterIssueCommentHandler(name string, fn IssueCommentHandler, help HelpProvider) {
pluginHelp[name] = help
issueCommentHandlers[name] = fn
}
|
go
|
func RegisterIssueCommentHandler(name string, fn IssueCommentHandler, help HelpProvider) {
pluginHelp[name] = help
issueCommentHandlers[name] = fn
}
|
[
"func",
"RegisterIssueCommentHandler",
"(",
"name",
"string",
",",
"fn",
"IssueCommentHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"issueCommentHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterIssueCommentHandler registers a plugin's github.IssueCommentEvent handler.
|
[
"RegisterIssueCommentHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"IssueCommentEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L74-L77
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterPullRequestHandler
|
func RegisterPullRequestHandler(name string, fn PullRequestHandler, help HelpProvider) {
pluginHelp[name] = help
pullRequestHandlers[name] = fn
}
|
go
|
func RegisterPullRequestHandler(name string, fn PullRequestHandler, help HelpProvider) {
pluginHelp[name] = help
pullRequestHandlers[name] = fn
}
|
[
"func",
"RegisterPullRequestHandler",
"(",
"name",
"string",
",",
"fn",
"PullRequestHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"pullRequestHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterPullRequestHandler registers a plugin's github.PullRequestEvent handler.
|
[
"RegisterPullRequestHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"PullRequestEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L83-L86
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterStatusEventHandler
|
func RegisterStatusEventHandler(name string, fn StatusEventHandler, help HelpProvider) {
pluginHelp[name] = help
statusEventHandlers[name] = fn
}
|
go
|
func RegisterStatusEventHandler(name string, fn StatusEventHandler, help HelpProvider) {
pluginHelp[name] = help
statusEventHandlers[name] = fn
}
|
[
"func",
"RegisterStatusEventHandler",
"(",
"name",
"string",
",",
"fn",
"StatusEventHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"statusEventHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterStatusEventHandler registers a plugin's github.StatusEvent handler.
|
[
"RegisterStatusEventHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"StatusEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L92-L95
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterPushEventHandler
|
func RegisterPushEventHandler(name string, fn PushEventHandler, help HelpProvider) {
pluginHelp[name] = help
pushEventHandlers[name] = fn
}
|
go
|
func RegisterPushEventHandler(name string, fn PushEventHandler, help HelpProvider) {
pluginHelp[name] = help
pushEventHandlers[name] = fn
}
|
[
"func",
"RegisterPushEventHandler",
"(",
"name",
"string",
",",
"fn",
"PushEventHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"pushEventHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterPushEventHandler registers a plugin's github.PushEvent handler.
|
[
"RegisterPushEventHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"PushEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L101-L104
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterReviewEventHandler
|
func RegisterReviewEventHandler(name string, fn ReviewEventHandler, help HelpProvider) {
pluginHelp[name] = help
reviewEventHandlers[name] = fn
}
|
go
|
func RegisterReviewEventHandler(name string, fn ReviewEventHandler, help HelpProvider) {
pluginHelp[name] = help
reviewEventHandlers[name] = fn
}
|
[
"func",
"RegisterReviewEventHandler",
"(",
"name",
"string",
",",
"fn",
"ReviewEventHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"reviewEventHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterReviewEventHandler registers a plugin's github.ReviewEvent handler.
|
[
"RegisterReviewEventHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"ReviewEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L110-L113
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterReviewCommentEventHandler
|
func RegisterReviewCommentEventHandler(name string, fn ReviewCommentEventHandler, help HelpProvider) {
pluginHelp[name] = help
reviewCommentEventHandlers[name] = fn
}
|
go
|
func RegisterReviewCommentEventHandler(name string, fn ReviewCommentEventHandler, help HelpProvider) {
pluginHelp[name] = help
reviewCommentEventHandlers[name] = fn
}
|
[
"func",
"RegisterReviewCommentEventHandler",
"(",
"name",
"string",
",",
"fn",
"ReviewCommentEventHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"reviewCommentEventHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterReviewCommentEventHandler registers a plugin's github.ReviewCommentEvent handler.
|
[
"RegisterReviewCommentEventHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"ReviewCommentEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L119-L122
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
RegisterGenericCommentHandler
|
func RegisterGenericCommentHandler(name string, fn GenericCommentHandler, help HelpProvider) {
pluginHelp[name] = help
genericCommentHandlers[name] = fn
}
|
go
|
func RegisterGenericCommentHandler(name string, fn GenericCommentHandler, help HelpProvider) {
pluginHelp[name] = help
genericCommentHandlers[name] = fn
}
|
[
"func",
"RegisterGenericCommentHandler",
"(",
"name",
"string",
",",
"fn",
"GenericCommentHandler",
",",
"help",
"HelpProvider",
")",
"{",
"pluginHelp",
"[",
"name",
"]",
"=",
"help",
"\n",
"genericCommentHandlers",
"[",
"name",
"]",
"=",
"fn",
"\n",
"}"
] |
// RegisterGenericCommentHandler registers a plugin's github.GenericCommentEvent handler.
|
[
"RegisterGenericCommentHandler",
"registers",
"a",
"plugin",
"s",
"github",
".",
"GenericCommentEvent",
"handler",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L128-L131
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
NewAgent
|
func NewAgent(configAgent *config.Agent, pluginConfigAgent *ConfigAgent, clientAgent *ClientAgent, logger *logrus.Entry) Agent {
prowConfig := configAgent.Config()
pluginConfig := pluginConfigAgent.Config()
return Agent{
GitHubClient: clientAgent.GitHubClient,
KubernetesClient: clientAgent.KubernetesClient,
ProwJobClient: clientAgent.ProwJobClient,
GitClient: clientAgent.GitClient,
SlackClient: clientAgent.SlackClient,
OwnersClient: clientAgent.OwnersClient,
Config: prowConfig,
PluginConfig: pluginConfig,
Logger: logger,
}
}
|
go
|
func NewAgent(configAgent *config.Agent, pluginConfigAgent *ConfigAgent, clientAgent *ClientAgent, logger *logrus.Entry) Agent {
prowConfig := configAgent.Config()
pluginConfig := pluginConfigAgent.Config()
return Agent{
GitHubClient: clientAgent.GitHubClient,
KubernetesClient: clientAgent.KubernetesClient,
ProwJobClient: clientAgent.ProwJobClient,
GitClient: clientAgent.GitClient,
SlackClient: clientAgent.SlackClient,
OwnersClient: clientAgent.OwnersClient,
Config: prowConfig,
PluginConfig: pluginConfig,
Logger: logger,
}
}
|
[
"func",
"NewAgent",
"(",
"configAgent",
"*",
"config",
".",
"Agent",
",",
"pluginConfigAgent",
"*",
"ConfigAgent",
",",
"clientAgent",
"*",
"ClientAgent",
",",
"logger",
"*",
"logrus",
".",
"Entry",
")",
"Agent",
"{",
"prowConfig",
":=",
"configAgent",
".",
"Config",
"(",
")",
"\n",
"pluginConfig",
":=",
"pluginConfigAgent",
".",
"Config",
"(",
")",
"\n",
"return",
"Agent",
"{",
"GitHubClient",
":",
"clientAgent",
".",
"GitHubClient",
",",
"KubernetesClient",
":",
"clientAgent",
".",
"KubernetesClient",
",",
"ProwJobClient",
":",
"clientAgent",
".",
"ProwJobClient",
",",
"GitClient",
":",
"clientAgent",
".",
"GitClient",
",",
"SlackClient",
":",
"clientAgent",
".",
"SlackClient",
",",
"OwnersClient",
":",
"clientAgent",
".",
"OwnersClient",
",",
"Config",
":",
"prowConfig",
",",
"PluginConfig",
":",
"pluginConfig",
",",
"Logger",
":",
"logger",
",",
"}",
"\n",
"}"
] |
// NewAgent bootstraps a new config.Agent struct from the passed dependencies.
|
[
"NewAgent",
"bootstraps",
"a",
"new",
"config",
".",
"Agent",
"struct",
"from",
"the",
"passed",
"dependencies",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L156-L170
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
InitializeCommentPruner
|
func (a *Agent) InitializeCommentPruner(org, repo string, pr int) {
a.commentPruner = commentpruner.NewEventClient(
a.GitHubClient, a.Logger.WithField("client", "commentpruner"),
org, repo, pr,
)
}
|
go
|
func (a *Agent) InitializeCommentPruner(org, repo string, pr int) {
a.commentPruner = commentpruner.NewEventClient(
a.GitHubClient, a.Logger.WithField("client", "commentpruner"),
org, repo, pr,
)
}
|
[
"func",
"(",
"a",
"*",
"Agent",
")",
"InitializeCommentPruner",
"(",
"org",
",",
"repo",
"string",
",",
"pr",
"int",
")",
"{",
"a",
".",
"commentPruner",
"=",
"commentpruner",
".",
"NewEventClient",
"(",
"a",
".",
"GitHubClient",
",",
"a",
".",
"Logger",
".",
"WithField",
"(",
"\"client\"",
",",
"\"commentpruner\"",
")",
",",
"org",
",",
"repo",
",",
"pr",
",",
")",
"\n",
"}"
] |
// InitializeCommentPruner attaches a commentpruner.EventClient to the agent to handle
// pruning comments.
|
[
"InitializeCommentPruner",
"attaches",
"a",
"commentpruner",
".",
"EventClient",
"to",
"the",
"agent",
"to",
"handle",
"pruning",
"comments",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L174-L179
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
CommentPruner
|
func (a *Agent) CommentPruner() (*commentpruner.EventClient, error) {
if a.commentPruner == nil {
return nil, errors.New("comment pruner client never initialized")
}
return a.commentPruner, nil
}
|
go
|
func (a *Agent) CommentPruner() (*commentpruner.EventClient, error) {
if a.commentPruner == nil {
return nil, errors.New("comment pruner client never initialized")
}
return a.commentPruner, nil
}
|
[
"func",
"(",
"a",
"*",
"Agent",
")",
"CommentPruner",
"(",
")",
"(",
"*",
"commentpruner",
".",
"EventClient",
",",
"error",
")",
"{",
"if",
"a",
".",
"commentPruner",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"comment pruner client never initialized\"",
")",
"\n",
"}",
"\n",
"return",
"a",
".",
"commentPruner",
",",
"nil",
"\n",
"}"
] |
// CommentPruner will return the commentpruner.EventClient attached to the agent or an error
// if one is not attached.
|
[
"CommentPruner",
"will",
"return",
"the",
"commentpruner",
".",
"EventClient",
"attached",
"to",
"the",
"agent",
"or",
"an",
"error",
"if",
"one",
"is",
"not",
"attached",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L183-L188
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
Load
|
func (pa *ConfigAgent) Load(path string) error {
b, err := ioutil.ReadFile(path)
if err != nil {
return err
}
np := &Configuration{}
if err := yaml.Unmarshal(b, np); err != nil {
return err
}
if err := np.Validate(); err != nil {
return err
}
pa.Set(np)
return nil
}
|
go
|
func (pa *ConfigAgent) Load(path string) error {
b, err := ioutil.ReadFile(path)
if err != nil {
return err
}
np := &Configuration{}
if err := yaml.Unmarshal(b, np); err != nil {
return err
}
if err := np.Validate(); err != nil {
return err
}
pa.Set(np)
return nil
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"Load",
"(",
"path",
"string",
")",
"error",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"np",
":=",
"&",
"Configuration",
"{",
"}",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"b",
",",
"np",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"np",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"pa",
".",
"Set",
"(",
"np",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Load attempts to load config from the path. It returns an error if either
// the file can't be read or the configuration is invalid.
|
[
"Load",
"attempts",
"to",
"load",
"config",
"from",
"the",
"path",
".",
"It",
"returns",
"an",
"error",
"if",
"either",
"the",
"file",
"can",
"t",
"be",
"read",
"or",
"the",
"configuration",
"is",
"invalid",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L208-L223
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
Config
|
func (pa *ConfigAgent) Config() *Configuration {
pa.mut.Lock()
defer pa.mut.Unlock()
return pa.configuration
}
|
go
|
func (pa *ConfigAgent) Config() *Configuration {
pa.mut.Lock()
defer pa.mut.Unlock()
return pa.configuration
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"Config",
"(",
")",
"*",
"Configuration",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"return",
"pa",
".",
"configuration",
"\n",
"}"
] |
// Config returns the agent current Configuration.
|
[
"Config",
"returns",
"the",
"agent",
"current",
"Configuration",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L226-L230
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
Set
|
func (pa *ConfigAgent) Set(pc *Configuration) {
pa.mut.Lock()
defer pa.mut.Unlock()
pa.configuration = pc
}
|
go
|
func (pa *ConfigAgent) Set(pc *Configuration) {
pa.mut.Lock()
defer pa.mut.Unlock()
pa.configuration = pc
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"Set",
"(",
"pc",
"*",
"Configuration",
")",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"pa",
".",
"configuration",
"=",
"pc",
"\n",
"}"
] |
// Set attempts to set the plugins that are enabled on repos. Plugins are listed
// as a map from repositories to the list of plugins that are enabled on them.
// Specifying simply an org name will also work, and will enable the plugin on
// all repos in the org.
|
[
"Set",
"attempts",
"to",
"set",
"the",
"plugins",
"that",
"are",
"enabled",
"on",
"repos",
".",
"Plugins",
"are",
"listed",
"as",
"a",
"map",
"from",
"repositories",
"to",
"the",
"list",
"of",
"plugins",
"that",
"are",
"enabled",
"on",
"them",
".",
"Specifying",
"simply",
"an",
"org",
"name",
"will",
"also",
"work",
"and",
"will",
"enable",
"the",
"plugin",
"on",
"all",
"repos",
"in",
"the",
"org",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L236-L240
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
Start
|
func (pa *ConfigAgent) Start(path string) error {
if err := pa.Load(path); err != nil {
return err
}
ticker := time.Tick(1 * time.Minute)
go func() {
for range ticker {
if err := pa.Load(path); err != nil {
logrus.WithField("path", path).WithError(err).Error("Error loading plugin config.")
}
}
}()
return nil
}
|
go
|
func (pa *ConfigAgent) Start(path string) error {
if err := pa.Load(path); err != nil {
return err
}
ticker := time.Tick(1 * time.Minute)
go func() {
for range ticker {
if err := pa.Load(path); err != nil {
logrus.WithField("path", path).WithError(err).Error("Error loading plugin config.")
}
}
}()
return nil
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"Start",
"(",
"path",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"pa",
".",
"Load",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ticker",
":=",
"time",
".",
"Tick",
"(",
"1",
"*",
"time",
".",
"Minute",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"range",
"ticker",
"{",
"if",
"err",
":=",
"pa",
".",
"Load",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithField",
"(",
"\"path\"",
",",
"path",
")",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"Error loading plugin config.\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Start starts polling path for plugin config. If the first attempt fails,
// then start returns the error. Future errors will halt updates but not stop.
|
[
"Start",
"starts",
"polling",
"path",
"for",
"plugin",
"config",
".",
"If",
"the",
"first",
"attempt",
"fails",
"then",
"start",
"returns",
"the",
"error",
".",
"Future",
"errors",
"will",
"halt",
"updates",
"but",
"not",
"stop",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L244-L257
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
GenericCommentHandlers
|
func (pa *ConfigAgent) GenericCommentHandlers(owner, repo string) map[string]GenericCommentHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]GenericCommentHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := genericCommentHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) GenericCommentHandlers(owner, repo string) map[string]GenericCommentHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]GenericCommentHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := genericCommentHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"GenericCommentHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"GenericCommentHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"GenericCommentHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"genericCommentHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// GenericCommentHandlers returns a map of plugin names to handlers for the repo.
|
[
"GenericCommentHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L260-L271
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
IssueHandlers
|
func (pa *ConfigAgent) IssueHandlers(owner, repo string) map[string]IssueHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]IssueHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := issueHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) IssueHandlers(owner, repo string) map[string]IssueHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]IssueHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := issueHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"IssueHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"IssueHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"IssueHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"issueHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// IssueHandlers returns a map of plugin names to handlers for the repo.
|
[
"IssueHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L274-L285
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
IssueCommentHandlers
|
func (pa *ConfigAgent) IssueCommentHandlers(owner, repo string) map[string]IssueCommentHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]IssueCommentHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := issueCommentHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) IssueCommentHandlers(owner, repo string) map[string]IssueCommentHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]IssueCommentHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := issueCommentHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"IssueCommentHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"IssueCommentHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"IssueCommentHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"issueCommentHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// IssueCommentHandlers returns a map of plugin names to handlers for the repo.
|
[
"IssueCommentHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L288-L300
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
PullRequestHandlers
|
func (pa *ConfigAgent) PullRequestHandlers(owner, repo string) map[string]PullRequestHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]PullRequestHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := pullRequestHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) PullRequestHandlers(owner, repo string) map[string]PullRequestHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]PullRequestHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := pullRequestHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"PullRequestHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"PullRequestHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"PullRequestHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"pullRequestHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// PullRequestHandlers returns a map of plugin names to handlers for the repo.
|
[
"PullRequestHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L303-L315
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
ReviewEventHandlers
|
func (pa *ConfigAgent) ReviewEventHandlers(owner, repo string) map[string]ReviewEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]ReviewEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := reviewEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) ReviewEventHandlers(owner, repo string) map[string]ReviewEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]ReviewEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := reviewEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"ReviewEventHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"ReviewEventHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"ReviewEventHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"reviewEventHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// ReviewEventHandlers returns a map of plugin names to handlers for the repo.
|
[
"ReviewEventHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L318-L330
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
ReviewCommentEventHandlers
|
func (pa *ConfigAgent) ReviewCommentEventHandlers(owner, repo string) map[string]ReviewCommentEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]ReviewCommentEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := reviewCommentEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) ReviewCommentEventHandlers(owner, repo string) map[string]ReviewCommentEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]ReviewCommentEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := reviewCommentEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"ReviewCommentEventHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"ReviewCommentEventHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"ReviewCommentEventHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"reviewCommentEventHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// ReviewCommentEventHandlers returns a map of plugin names to handlers for the repo.
|
[
"ReviewCommentEventHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L333-L345
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
StatusEventHandlers
|
func (pa *ConfigAgent) StatusEventHandlers(owner, repo string) map[string]StatusEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]StatusEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := statusEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) StatusEventHandlers(owner, repo string) map[string]StatusEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]StatusEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := statusEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"StatusEventHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"StatusEventHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"StatusEventHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"statusEventHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// StatusEventHandlers returns a map of plugin names to handlers for the repo.
|
[
"StatusEventHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L348-L360
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
PushEventHandlers
|
func (pa *ConfigAgent) PushEventHandlers(owner, repo string) map[string]PushEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]PushEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := pushEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
go
|
func (pa *ConfigAgent) PushEventHandlers(owner, repo string) map[string]PushEventHandler {
pa.mut.Lock()
defer pa.mut.Unlock()
hs := map[string]PushEventHandler{}
for _, p := range pa.getPlugins(owner, repo) {
if h, ok := pushEventHandlers[p]; ok {
hs[p] = h
}
}
return hs
}
|
[
"func",
"(",
"pa",
"*",
"ConfigAgent",
")",
"PushEventHandlers",
"(",
"owner",
",",
"repo",
"string",
")",
"map",
"[",
"string",
"]",
"PushEventHandler",
"{",
"pa",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pa",
".",
"mut",
".",
"Unlock",
"(",
")",
"\n",
"hs",
":=",
"map",
"[",
"string",
"]",
"PushEventHandler",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"pa",
".",
"getPlugins",
"(",
"owner",
",",
"repo",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"pushEventHandlers",
"[",
"p",
"]",
";",
"ok",
"{",
"hs",
"[",
"p",
"]",
"=",
"h",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hs",
"\n",
"}"
] |
// PushEventHandlers returns a map of plugin names to handlers for the repo.
|
[
"PushEventHandlers",
"returns",
"a",
"map",
"of",
"plugin",
"names",
"to",
"handlers",
"for",
"the",
"repo",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L363-L375
|
test
|
kubernetes/test-infra
|
prow/plugins/plugins.go
|
EventsForPlugin
|
func EventsForPlugin(name string) []string {
var events []string
if _, ok := issueHandlers[name]; ok {
events = append(events, "issue")
}
if _, ok := issueCommentHandlers[name]; ok {
events = append(events, "issue_comment")
}
if _, ok := pullRequestHandlers[name]; ok {
events = append(events, "pull_request")
}
if _, ok := pushEventHandlers[name]; ok {
events = append(events, "push")
}
if _, ok := reviewEventHandlers[name]; ok {
events = append(events, "pull_request_review")
}
if _, ok := reviewCommentEventHandlers[name]; ok {
events = append(events, "pull_request_review_comment")
}
if _, ok := statusEventHandlers[name]; ok {
events = append(events, "status")
}
if _, ok := genericCommentHandlers[name]; ok {
events = append(events, "GenericCommentEvent (any event for user text)")
}
return events
}
|
go
|
func EventsForPlugin(name string) []string {
var events []string
if _, ok := issueHandlers[name]; ok {
events = append(events, "issue")
}
if _, ok := issueCommentHandlers[name]; ok {
events = append(events, "issue_comment")
}
if _, ok := pullRequestHandlers[name]; ok {
events = append(events, "pull_request")
}
if _, ok := pushEventHandlers[name]; ok {
events = append(events, "push")
}
if _, ok := reviewEventHandlers[name]; ok {
events = append(events, "pull_request_review")
}
if _, ok := reviewCommentEventHandlers[name]; ok {
events = append(events, "pull_request_review_comment")
}
if _, ok := statusEventHandlers[name]; ok {
events = append(events, "status")
}
if _, ok := genericCommentHandlers[name]; ok {
events = append(events, "GenericCommentEvent (any event for user text)")
}
return events
}
|
[
"func",
"EventsForPlugin",
"(",
"name",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"events",
"[",
"]",
"string",
"\n",
"if",
"_",
",",
"ok",
":=",
"issueHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"issue\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"issueCommentHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"issue_comment\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"pullRequestHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"pull_request\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"pushEventHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"push\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"reviewEventHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"pull_request_review\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"reviewCommentEventHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"pull_request_review_comment\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"statusEventHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"status\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"genericCommentHandlers",
"[",
"name",
"]",
";",
"ok",
"{",
"events",
"=",
"append",
"(",
"events",
",",
"\"GenericCommentEvent (any event for user text)\"",
")",
"\n",
"}",
"\n",
"return",
"events",
"\n",
"}"
] |
// EventsForPlugin returns the registered events for the passed plugin.
|
[
"EventsForPlugin",
"returns",
"the",
"registered",
"events",
"for",
"the",
"passed",
"plugin",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/plugins.go#L389-L416
|
test
|
kubernetes/test-infra
|
experiment/resultstore/main.go
|
insertLink
|
func insertLink(started *gcs.Started, viewURL string) (bool, error) {
if started.Metadata == nil {
started.Metadata = metadata.Metadata{}
}
meta := started.Metadata
var changed bool
top, present := meta.String(resultstoreKey)
if !present || top == nil || *top != viewURL {
changed = true
meta[resultstoreKey] = viewURL
}
links, present := meta.Meta(linksKey)
if present && links == nil {
return false, fmt.Errorf("metadata.links is not a Metadata value: %v", meta[linksKey])
}
if links == nil {
links = &metadata.Metadata{}
changed = true
}
resultstoreMeta, present := links.Meta(resultstoreKey)
if present && resultstoreMeta == nil {
return false, fmt.Errorf("metadata.links.resultstore is not a Metadata value: %v", (*links)[resultstoreKey])
}
if resultstoreMeta == nil {
resultstoreMeta = &metadata.Metadata{}
changed = true
}
val, present := resultstoreMeta.String(urlKey)
if present && val == nil {
return false, fmt.Errorf("metadata.links.resultstore.url is not a string value: %v", (*resultstoreMeta)[urlKey])
}
if !changed && val != nil && *val == viewURL {
return false, nil
}
(*resultstoreMeta)[urlKey] = viewURL
(*links)[resultstoreKey] = *resultstoreMeta
meta[linksKey] = *links
return true, nil
}
|
go
|
func insertLink(started *gcs.Started, viewURL string) (bool, error) {
if started.Metadata == nil {
started.Metadata = metadata.Metadata{}
}
meta := started.Metadata
var changed bool
top, present := meta.String(resultstoreKey)
if !present || top == nil || *top != viewURL {
changed = true
meta[resultstoreKey] = viewURL
}
links, present := meta.Meta(linksKey)
if present && links == nil {
return false, fmt.Errorf("metadata.links is not a Metadata value: %v", meta[linksKey])
}
if links == nil {
links = &metadata.Metadata{}
changed = true
}
resultstoreMeta, present := links.Meta(resultstoreKey)
if present && resultstoreMeta == nil {
return false, fmt.Errorf("metadata.links.resultstore is not a Metadata value: %v", (*links)[resultstoreKey])
}
if resultstoreMeta == nil {
resultstoreMeta = &metadata.Metadata{}
changed = true
}
val, present := resultstoreMeta.String(urlKey)
if present && val == nil {
return false, fmt.Errorf("metadata.links.resultstore.url is not a string value: %v", (*resultstoreMeta)[urlKey])
}
if !changed && val != nil && *val == viewURL {
return false, nil
}
(*resultstoreMeta)[urlKey] = viewURL
(*links)[resultstoreKey] = *resultstoreMeta
meta[linksKey] = *links
return true, nil
}
|
[
"func",
"insertLink",
"(",
"started",
"*",
"gcs",
".",
"Started",
",",
"viewURL",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"started",
".",
"Metadata",
"==",
"nil",
"{",
"started",
".",
"Metadata",
"=",
"metadata",
".",
"Metadata",
"{",
"}",
"\n",
"}",
"\n",
"meta",
":=",
"started",
".",
"Metadata",
"\n",
"var",
"changed",
"bool",
"\n",
"top",
",",
"present",
":=",
"meta",
".",
"String",
"(",
"resultstoreKey",
")",
"\n",
"if",
"!",
"present",
"||",
"top",
"==",
"nil",
"||",
"*",
"top",
"!=",
"viewURL",
"{",
"changed",
"=",
"true",
"\n",
"meta",
"[",
"resultstoreKey",
"]",
"=",
"viewURL",
"\n",
"}",
"\n",
"links",
",",
"present",
":=",
"meta",
".",
"Meta",
"(",
"linksKey",
")",
"\n",
"if",
"present",
"&&",
"links",
"==",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"metadata.links is not a Metadata value: %v\"",
",",
"meta",
"[",
"linksKey",
"]",
")",
"\n",
"}",
"\n",
"if",
"links",
"==",
"nil",
"{",
"links",
"=",
"&",
"metadata",
".",
"Metadata",
"{",
"}",
"\n",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"resultstoreMeta",
",",
"present",
":=",
"links",
".",
"Meta",
"(",
"resultstoreKey",
")",
"\n",
"if",
"present",
"&&",
"resultstoreMeta",
"==",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"metadata.links.resultstore is not a Metadata value: %v\"",
",",
"(",
"*",
"links",
")",
"[",
"resultstoreKey",
"]",
")",
"\n",
"}",
"\n",
"if",
"resultstoreMeta",
"==",
"nil",
"{",
"resultstoreMeta",
"=",
"&",
"metadata",
".",
"Metadata",
"{",
"}",
"\n",
"changed",
"=",
"true",
"\n",
"}",
"\n",
"val",
",",
"present",
":=",
"resultstoreMeta",
".",
"String",
"(",
"urlKey",
")",
"\n",
"if",
"present",
"&&",
"val",
"==",
"nil",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"metadata.links.resultstore.url is not a string value: %v\"",
",",
"(",
"*",
"resultstoreMeta",
")",
"[",
"urlKey",
"]",
")",
"\n",
"}",
"\n",
"if",
"!",
"changed",
"&&",
"val",
"!=",
"nil",
"&&",
"*",
"val",
"==",
"viewURL",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"(",
"*",
"resultstoreMeta",
")",
"[",
"urlKey",
"]",
"=",
"viewURL",
"\n",
"(",
"*",
"links",
")",
"[",
"resultstoreKey",
"]",
"=",
"*",
"resultstoreMeta",
"\n",
"meta",
"[",
"linksKey",
"]",
"=",
"*",
"links",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] |
// insertLink attempts to set metadata.links.resultstore.url to viewURL.
//
// returns true if started metadata was updated.
|
[
"insertLink",
"attempts",
"to",
"set",
"metadata",
".",
"links",
".",
"resultstore",
".",
"url",
"to",
"viewURL",
".",
"returns",
"true",
"if",
"started",
"metadata",
"was",
"updated",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/experiment/resultstore/main.go#L487-L526
|
test
|
kubernetes/test-infra
|
prow/external-plugins/cherrypicker/server.go
|
HelpProvider
|
func HelpProvider(enabledRepos []string) (*pluginhelp.PluginHelp, error) {
pluginHelp := &pluginhelp.PluginHelp{
Description: `The cherrypick plugin is used for cherrypicking PRs across branches. For every successful cherrypick invocation a new PR is opened against the target branch and assigned to the requester. If the parent PR contains a release note, it is copied to the cherrypick PR.`,
}
pluginHelp.AddCommand(pluginhelp.Command{
Usage: "/cherrypick [branch]",
Description: "Cherrypick a PR to a different branch. This command works both in merged PRs (the cherrypick PR is opened immediately) and open PRs (the cherrypick PR opens as soon as the original PR merges).",
Featured: true,
// depends on how the cherrypick server runs; needs auth by default (--allow-all=false)
WhoCanUse: "Members of the trusted organization for the repo.",
Examples: []string{"/cherrypick release-3.9"},
})
return pluginHelp, nil
}
|
go
|
func HelpProvider(enabledRepos []string) (*pluginhelp.PluginHelp, error) {
pluginHelp := &pluginhelp.PluginHelp{
Description: `The cherrypick plugin is used for cherrypicking PRs across branches. For every successful cherrypick invocation a new PR is opened against the target branch and assigned to the requester. If the parent PR contains a release note, it is copied to the cherrypick PR.`,
}
pluginHelp.AddCommand(pluginhelp.Command{
Usage: "/cherrypick [branch]",
Description: "Cherrypick a PR to a different branch. This command works both in merged PRs (the cherrypick PR is opened immediately) and open PRs (the cherrypick PR opens as soon as the original PR merges).",
Featured: true,
// depends on how the cherrypick server runs; needs auth by default (--allow-all=false)
WhoCanUse: "Members of the trusted organization for the repo.",
Examples: []string{"/cherrypick release-3.9"},
})
return pluginHelp, nil
}
|
[
"func",
"HelpProvider",
"(",
"enabledRepos",
"[",
"]",
"string",
")",
"(",
"*",
"pluginhelp",
".",
"PluginHelp",
",",
"error",
")",
"{",
"pluginHelp",
":=",
"&",
"pluginhelp",
".",
"PluginHelp",
"{",
"Description",
":",
"`The cherrypick plugin is used for cherrypicking PRs across branches. For every successful cherrypick invocation a new PR is opened against the target branch and assigned to the requester. If the parent PR contains a release note, it is copied to the cherrypick PR.`",
",",
"}",
"\n",
"pluginHelp",
".",
"AddCommand",
"(",
"pluginhelp",
".",
"Command",
"{",
"Usage",
":",
"\"/cherrypick [branch]\"",
",",
"Description",
":",
"\"Cherrypick a PR to a different branch. This command works both in merged PRs (the cherrypick PR is opened immediately) and open PRs (the cherrypick PR opens as soon as the original PR merges).\"",
",",
"Featured",
":",
"true",
",",
"WhoCanUse",
":",
"\"Members of the trusted organization for the repo.\"",
",",
"Examples",
":",
"[",
"]",
"string",
"{",
"\"/cherrypick release-3.9\"",
"}",
",",
"}",
")",
"\n",
"return",
"pluginHelp",
",",
"nil",
"\n",
"}"
] |
// HelpProvider construct the pluginhelp.PluginHelp for this plugin.
|
[
"HelpProvider",
"construct",
"the",
"pluginhelp",
".",
"PluginHelp",
"for",
"this",
"plugin",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/external-plugins/cherrypicker/server.go#L58-L71
|
test
|
kubernetes/test-infra
|
prow/external-plugins/cherrypicker/server.go
|
getPatch
|
func (s *Server) getPatch(org, repo, targetBranch string, num int) (string, error) {
patch, err := s.ghc.GetPullRequestPatch(org, repo, num)
if err != nil {
return "", err
}
localPath := fmt.Sprintf("/tmp/%s_%s_%d_%s.patch", org, repo, num, normalize(targetBranch))
out, err := os.Create(localPath)
if err != nil {
return "", err
}
defer out.Close()
if _, err := io.Copy(out, bytes.NewBuffer(patch)); err != nil {
return "", err
}
return localPath, nil
}
|
go
|
func (s *Server) getPatch(org, repo, targetBranch string, num int) (string, error) {
patch, err := s.ghc.GetPullRequestPatch(org, repo, num)
if err != nil {
return "", err
}
localPath := fmt.Sprintf("/tmp/%s_%s_%d_%s.patch", org, repo, num, normalize(targetBranch))
out, err := os.Create(localPath)
if err != nil {
return "", err
}
defer out.Close()
if _, err := io.Copy(out, bytes.NewBuffer(patch)); err != nil {
return "", err
}
return localPath, nil
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"getPatch",
"(",
"org",
",",
"repo",
",",
"targetBranch",
"string",
",",
"num",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"patch",
",",
"err",
":=",
"s",
".",
"ghc",
".",
"GetPullRequestPatch",
"(",
"org",
",",
"repo",
",",
"num",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"localPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"/tmp/%s_%s_%d_%s.patch\"",
",",
"org",
",",
"repo",
",",
"num",
",",
"normalize",
"(",
"targetBranch",
")",
")",
"\n",
"out",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"localPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"out",
".",
"Close",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"out",
",",
"bytes",
".",
"NewBuffer",
"(",
"patch",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"localPath",
",",
"nil",
"\n",
"}"
] |
// getPatch gets the patch for the provided PR and creates a local
// copy of it. It returns its location in the filesystem and any
// encountered error.
|
[
"getPatch",
"gets",
"the",
"patch",
"for",
"the",
"provided",
"PR",
"and",
"creates",
"a",
"local",
"copy",
"of",
"it",
".",
"It",
"returns",
"its",
"location",
"in",
"the",
"filesystem",
"and",
"any",
"encountered",
"error",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/external-plugins/cherrypicker/server.go#L484-L499
|
test
|
kubernetes/test-infra
|
prow/external-plugins/cherrypicker/server.go
|
releaseNoteFromParentPR
|
func releaseNoteFromParentPR(body string) string {
potentialMatch := releaseNoteRe.FindStringSubmatch(body)
if potentialMatch == nil {
return ""
}
return fmt.Sprintf("```release-note\n%s\n```", strings.TrimSpace(potentialMatch[1]))
}
|
go
|
func releaseNoteFromParentPR(body string) string {
potentialMatch := releaseNoteRe.FindStringSubmatch(body)
if potentialMatch == nil {
return ""
}
return fmt.Sprintf("```release-note\n%s\n```", strings.TrimSpace(potentialMatch[1]))
}
|
[
"func",
"releaseNoteFromParentPR",
"(",
"body",
"string",
")",
"string",
"{",
"potentialMatch",
":=",
"releaseNoteRe",
".",
"FindStringSubmatch",
"(",
"body",
")",
"\n",
"if",
"potentialMatch",
"==",
"nil",
"{",
"return",
"\"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"```release-note\\n%s\\n```\"",
",",
"\\n",
")",
"\n",
"}"
] |
// releaseNoteNoteFromParentPR gets the release note from the
// parent PR and formats it as per the PR template so that
// it can be copied to the cherry-pick PR.
|
[
"releaseNoteNoteFromParentPR",
"gets",
"the",
"release",
"note",
"from",
"the",
"parent",
"PR",
"and",
"formats",
"it",
"as",
"per",
"the",
"PR",
"template",
"so",
"that",
"it",
"can",
"be",
"copied",
"to",
"the",
"cherry",
"-",
"pick",
"PR",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/external-plugins/cherrypicker/server.go#L508-L514
|
test
|
kubernetes/test-infra
|
prow/github/hmac.go
|
ValidatePayload
|
func ValidatePayload(payload []byte, sig string, key []byte) bool {
if !strings.HasPrefix(sig, "sha1=") {
return false
}
sig = sig[5:]
sb, err := hex.DecodeString(sig)
if err != nil {
return false
}
mac := hmac.New(sha1.New, key)
mac.Write(payload)
expected := mac.Sum(nil)
return hmac.Equal(sb, expected)
}
|
go
|
func ValidatePayload(payload []byte, sig string, key []byte) bool {
if !strings.HasPrefix(sig, "sha1=") {
return false
}
sig = sig[5:]
sb, err := hex.DecodeString(sig)
if err != nil {
return false
}
mac := hmac.New(sha1.New, key)
mac.Write(payload)
expected := mac.Sum(nil)
return hmac.Equal(sb, expected)
}
|
[
"func",
"ValidatePayload",
"(",
"payload",
"[",
"]",
"byte",
",",
"sig",
"string",
",",
"key",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"sig",
",",
"\"sha1=\"",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"sig",
"=",
"sig",
"[",
"5",
":",
"]",
"\n",
"sb",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"sig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"key",
")",
"\n",
"mac",
".",
"Write",
"(",
"payload",
")",
"\n",
"expected",
":=",
"mac",
".",
"Sum",
"(",
"nil",
")",
"\n",
"return",
"hmac",
".",
"Equal",
"(",
"sb",
",",
"expected",
")",
"\n",
"}"
] |
// ValidatePayload ensures that the request payload signature matches the key.
|
[
"ValidatePayload",
"ensures",
"that",
"the",
"request",
"payload",
"signature",
"matches",
"the",
"key",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/hmac.go#L27-L40
|
test
|
kubernetes/test-infra
|
prow/github/hmac.go
|
PayloadSignature
|
func PayloadSignature(payload []byte, key []byte) string {
mac := hmac.New(sha1.New, key)
mac.Write(payload)
sum := mac.Sum(nil)
return "sha1=" + hex.EncodeToString(sum)
}
|
go
|
func PayloadSignature(payload []byte, key []byte) string {
mac := hmac.New(sha1.New, key)
mac.Write(payload)
sum := mac.Sum(nil)
return "sha1=" + hex.EncodeToString(sum)
}
|
[
"func",
"PayloadSignature",
"(",
"payload",
"[",
"]",
"byte",
",",
"key",
"[",
"]",
"byte",
")",
"string",
"{",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"key",
")",
"\n",
"mac",
".",
"Write",
"(",
"payload",
")",
"\n",
"sum",
":=",
"mac",
".",
"Sum",
"(",
"nil",
")",
"\n",
"return",
"\"sha1=\"",
"+",
"hex",
".",
"EncodeToString",
"(",
"sum",
")",
"\n",
"}"
] |
// PayloadSignature returns the signature that matches the payload.
|
[
"PayloadSignature",
"returns",
"the",
"signature",
"that",
"matches",
"the",
"payload",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/hmac.go#L43-L48
|
test
|
kubernetes/test-infra
|
prow/cmd/peribolos/main.go
|
updateString
|
func updateString(have, want *string) bool {
switch {
case have == nil:
panic("have must be non-nil")
case want == nil:
return false // do not care what we have
case *have == *want:
return false // already have it
}
*have = *want // update value
return true
}
|
go
|
func updateString(have, want *string) bool {
switch {
case have == nil:
panic("have must be non-nil")
case want == nil:
return false // do not care what we have
case *have == *want:
return false // already have it
}
*have = *want // update value
return true
}
|
[
"func",
"updateString",
"(",
"have",
",",
"want",
"*",
"string",
")",
"bool",
"{",
"switch",
"{",
"case",
"have",
"==",
"nil",
":",
"panic",
"(",
"\"have must be non-nil\"",
")",
"\n",
"case",
"want",
"==",
"nil",
":",
"return",
"false",
"\n",
"case",
"*",
"have",
"==",
"*",
"want",
":",
"return",
"false",
"\n",
"}",
"\n",
"*",
"have",
"=",
"*",
"want",
"\n",
"return",
"true",
"\n",
"}"
] |
// updateString will return true and set have to want iff they are set and different.
|
[
"updateString",
"will",
"return",
"true",
"and",
"set",
"have",
"to",
"want",
"iff",
"they",
"are",
"set",
"and",
"different",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cmd/peribolos/main.go#L686-L697
|
test
|
kubernetes/test-infra
|
prow/cmd/peribolos/main.go
|
updateBool
|
func updateBool(have, want *bool) bool {
switch {
case have == nil:
panic("have must not be nil")
case want == nil:
return false // do not care what we have
case *have == *want:
return false //already have it
}
*have = *want // update value
return true
}
|
go
|
func updateBool(have, want *bool) bool {
switch {
case have == nil:
panic("have must not be nil")
case want == nil:
return false // do not care what we have
case *have == *want:
return false //already have it
}
*have = *want // update value
return true
}
|
[
"func",
"updateBool",
"(",
"have",
",",
"want",
"*",
"bool",
")",
"bool",
"{",
"switch",
"{",
"case",
"have",
"==",
"nil",
":",
"panic",
"(",
"\"have must not be nil\"",
")",
"\n",
"case",
"want",
"==",
"nil",
":",
"return",
"false",
"\n",
"case",
"*",
"have",
"==",
"*",
"want",
":",
"return",
"false",
"\n",
"}",
"\n",
"*",
"have",
"=",
"*",
"want",
"\n",
"return",
"true",
"\n",
"}"
] |
// updateBool will return true and set have to want iff they are set and different.
|
[
"updateBool",
"will",
"return",
"true",
"and",
"set",
"have",
"to",
"want",
"iff",
"they",
"are",
"set",
"and",
"different",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cmd/peribolos/main.go#L700-L711
|
test
|
kubernetes/test-infra
|
prow/cmd/peribolos/main.go
|
configureOrgMeta
|
func configureOrgMeta(client orgMetadataClient, orgName string, want org.Metadata) error {
cur, err := client.GetOrg(orgName)
if err != nil {
return fmt.Errorf("failed to get %s metadata: %v", orgName, err)
}
change := false
change = updateString(&cur.BillingEmail, want.BillingEmail) || change
change = updateString(&cur.Company, want.Company) || change
change = updateString(&cur.Email, want.Email) || change
change = updateString(&cur.Name, want.Name) || change
change = updateString(&cur.Description, want.Description) || change
change = updateString(&cur.Location, want.Location) || change
if want.DefaultRepositoryPermission != nil {
w := string(*want.DefaultRepositoryPermission)
change = updateString(&cur.DefaultRepositoryPermission, &w)
}
change = updateBool(&cur.HasOrganizationProjects, want.HasOrganizationProjects) || change
change = updateBool(&cur.HasRepositoryProjects, want.HasRepositoryProjects) || change
change = updateBool(&cur.MembersCanCreateRepositories, want.MembersCanCreateRepositories) || change
if change {
if _, err := client.EditOrg(orgName, *cur); err != nil {
return fmt.Errorf("failed to edit %s metadata: %v", orgName, err)
}
}
return nil
}
|
go
|
func configureOrgMeta(client orgMetadataClient, orgName string, want org.Metadata) error {
cur, err := client.GetOrg(orgName)
if err != nil {
return fmt.Errorf("failed to get %s metadata: %v", orgName, err)
}
change := false
change = updateString(&cur.BillingEmail, want.BillingEmail) || change
change = updateString(&cur.Company, want.Company) || change
change = updateString(&cur.Email, want.Email) || change
change = updateString(&cur.Name, want.Name) || change
change = updateString(&cur.Description, want.Description) || change
change = updateString(&cur.Location, want.Location) || change
if want.DefaultRepositoryPermission != nil {
w := string(*want.DefaultRepositoryPermission)
change = updateString(&cur.DefaultRepositoryPermission, &w)
}
change = updateBool(&cur.HasOrganizationProjects, want.HasOrganizationProjects) || change
change = updateBool(&cur.HasRepositoryProjects, want.HasRepositoryProjects) || change
change = updateBool(&cur.MembersCanCreateRepositories, want.MembersCanCreateRepositories) || change
if change {
if _, err := client.EditOrg(orgName, *cur); err != nil {
return fmt.Errorf("failed to edit %s metadata: %v", orgName, err)
}
}
return nil
}
|
[
"func",
"configureOrgMeta",
"(",
"client",
"orgMetadataClient",
",",
"orgName",
"string",
",",
"want",
"org",
".",
"Metadata",
")",
"error",
"{",
"cur",
",",
"err",
":=",
"client",
".",
"GetOrg",
"(",
"orgName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to get %s metadata: %v\"",
",",
"orgName",
",",
"err",
")",
"\n",
"}",
"\n",
"change",
":=",
"false",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"BillingEmail",
",",
"want",
".",
"BillingEmail",
")",
"||",
"change",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"Company",
",",
"want",
".",
"Company",
")",
"||",
"change",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"Email",
",",
"want",
".",
"Email",
")",
"||",
"change",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"Name",
",",
"want",
".",
"Name",
")",
"||",
"change",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"Description",
",",
"want",
".",
"Description",
")",
"||",
"change",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"Location",
",",
"want",
".",
"Location",
")",
"||",
"change",
"\n",
"if",
"want",
".",
"DefaultRepositoryPermission",
"!=",
"nil",
"{",
"w",
":=",
"string",
"(",
"*",
"want",
".",
"DefaultRepositoryPermission",
")",
"\n",
"change",
"=",
"updateString",
"(",
"&",
"cur",
".",
"DefaultRepositoryPermission",
",",
"&",
"w",
")",
"\n",
"}",
"\n",
"change",
"=",
"updateBool",
"(",
"&",
"cur",
".",
"HasOrganizationProjects",
",",
"want",
".",
"HasOrganizationProjects",
")",
"||",
"change",
"\n",
"change",
"=",
"updateBool",
"(",
"&",
"cur",
".",
"HasRepositoryProjects",
",",
"want",
".",
"HasRepositoryProjects",
")",
"||",
"change",
"\n",
"change",
"=",
"updateBool",
"(",
"&",
"cur",
".",
"MembersCanCreateRepositories",
",",
"want",
".",
"MembersCanCreateRepositories",
")",
"||",
"change",
"\n",
"if",
"change",
"{",
"if",
"_",
",",
"err",
":=",
"client",
".",
"EditOrg",
"(",
"orgName",
",",
"*",
"cur",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to edit %s metadata: %v\"",
",",
"orgName",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// configureOrgMeta will update github to have the non-nil wanted metadata values.
|
[
"configureOrgMeta",
"will",
"update",
"github",
"to",
"have",
"the",
"non",
"-",
"nil",
"wanted",
"metadata",
"values",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cmd/peribolos/main.go#L719-L744
|
test
|
kubernetes/test-infra
|
prow/cmd/peribolos/main.go
|
configureTeamRepos
|
func configureTeamRepos(client teamRepoClient, githubTeams map[string]github.Team, name, orgName string, team org.Team) error {
gt, ok := githubTeams[name]
if !ok { // configureTeams is buggy if this is the case
return fmt.Errorf("%s not found in id list", name)
}
want := team.Repos
have := map[string]github.RepoPermissionLevel{}
repos, err := client.ListTeamRepos(gt.ID)
if err != nil {
return fmt.Errorf("failed to list team %d(%s) repos: %v", gt.ID, name, err)
}
for _, repo := range repos {
have[repo.Name] = github.LevelFromPermissions(repo.Permissions)
}
actions := map[string]github.RepoPermissionLevel{}
for wantRepo, wantPermission := range want {
if havePermission, haveRepo := have[wantRepo]; haveRepo && havePermission == wantPermission {
// nothing to do
continue
}
// create or update this permission
actions[wantRepo] = wantPermission
}
for haveRepo := range have {
if _, wantRepo := want[haveRepo]; !wantRepo {
// should remove these permissions
actions[haveRepo] = github.None
}
}
var updateErrors []error
for repo, permission := range actions {
var err error
if permission == github.None {
err = client.RemoveTeamRepo(gt.ID, orgName, repo)
} else {
err = client.UpdateTeamRepo(gt.ID, orgName, repo, permission)
}
if err != nil {
updateErrors = append(updateErrors, fmt.Errorf("failed to update team %d(%s) permissions on repo %s to %s: %v", gt.ID, name, repo, permission, err))
}
}
return errorutil.NewAggregate(updateErrors...)
}
|
go
|
func configureTeamRepos(client teamRepoClient, githubTeams map[string]github.Team, name, orgName string, team org.Team) error {
gt, ok := githubTeams[name]
if !ok { // configureTeams is buggy if this is the case
return fmt.Errorf("%s not found in id list", name)
}
want := team.Repos
have := map[string]github.RepoPermissionLevel{}
repos, err := client.ListTeamRepos(gt.ID)
if err != nil {
return fmt.Errorf("failed to list team %d(%s) repos: %v", gt.ID, name, err)
}
for _, repo := range repos {
have[repo.Name] = github.LevelFromPermissions(repo.Permissions)
}
actions := map[string]github.RepoPermissionLevel{}
for wantRepo, wantPermission := range want {
if havePermission, haveRepo := have[wantRepo]; haveRepo && havePermission == wantPermission {
// nothing to do
continue
}
// create or update this permission
actions[wantRepo] = wantPermission
}
for haveRepo := range have {
if _, wantRepo := want[haveRepo]; !wantRepo {
// should remove these permissions
actions[haveRepo] = github.None
}
}
var updateErrors []error
for repo, permission := range actions {
var err error
if permission == github.None {
err = client.RemoveTeamRepo(gt.ID, orgName, repo)
} else {
err = client.UpdateTeamRepo(gt.ID, orgName, repo, permission)
}
if err != nil {
updateErrors = append(updateErrors, fmt.Errorf("failed to update team %d(%s) permissions on repo %s to %s: %v", gt.ID, name, repo, permission, err))
}
}
return errorutil.NewAggregate(updateErrors...)
}
|
[
"func",
"configureTeamRepos",
"(",
"client",
"teamRepoClient",
",",
"githubTeams",
"map",
"[",
"string",
"]",
"github",
".",
"Team",
",",
"name",
",",
"orgName",
"string",
",",
"team",
"org",
".",
"Team",
")",
"error",
"{",
"gt",
",",
"ok",
":=",
"githubTeams",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"%s not found in id list\"",
",",
"name",
")",
"\n",
"}",
"\n",
"want",
":=",
"team",
".",
"Repos",
"\n",
"have",
":=",
"map",
"[",
"string",
"]",
"github",
".",
"RepoPermissionLevel",
"{",
"}",
"\n",
"repos",
",",
"err",
":=",
"client",
".",
"ListTeamRepos",
"(",
"gt",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to list team %d(%s) repos: %v\"",
",",
"gt",
".",
"ID",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"repo",
":=",
"range",
"repos",
"{",
"have",
"[",
"repo",
".",
"Name",
"]",
"=",
"github",
".",
"LevelFromPermissions",
"(",
"repo",
".",
"Permissions",
")",
"\n",
"}",
"\n",
"actions",
":=",
"map",
"[",
"string",
"]",
"github",
".",
"RepoPermissionLevel",
"{",
"}",
"\n",
"for",
"wantRepo",
",",
"wantPermission",
":=",
"range",
"want",
"{",
"if",
"havePermission",
",",
"haveRepo",
":=",
"have",
"[",
"wantRepo",
"]",
";",
"haveRepo",
"&&",
"havePermission",
"==",
"wantPermission",
"{",
"continue",
"\n",
"}",
"\n",
"actions",
"[",
"wantRepo",
"]",
"=",
"wantPermission",
"\n",
"}",
"\n",
"for",
"haveRepo",
":=",
"range",
"have",
"{",
"if",
"_",
",",
"wantRepo",
":=",
"want",
"[",
"haveRepo",
"]",
";",
"!",
"wantRepo",
"{",
"actions",
"[",
"haveRepo",
"]",
"=",
"github",
".",
"None",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"updateErrors",
"[",
"]",
"error",
"\n",
"for",
"repo",
",",
"permission",
":=",
"range",
"actions",
"{",
"var",
"err",
"error",
"\n",
"if",
"permission",
"==",
"github",
".",
"None",
"{",
"err",
"=",
"client",
".",
"RemoveTeamRepo",
"(",
"gt",
".",
"ID",
",",
"orgName",
",",
"repo",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"client",
".",
"UpdateTeamRepo",
"(",
"gt",
".",
"ID",
",",
"orgName",
",",
"repo",
",",
"permission",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"updateErrors",
"=",
"append",
"(",
"updateErrors",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to update team %d(%s) permissions on repo %s to %s: %v\"",
",",
"gt",
".",
"ID",
",",
"name",
",",
"repo",
",",
"permission",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"errorutil",
".",
"NewAggregate",
"(",
"updateErrors",
"...",
")",
"\n",
"}"
] |
// configureTeamRepos updates the list of repos that the team has permissions for when necessary
|
[
"configureTeamRepos",
"updates",
"the",
"list",
"of",
"repos",
"that",
"the",
"team",
"has",
"permissions",
"for",
"when",
"necessary"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cmd/peribolos/main.go#L904-L951
|
test
|
kubernetes/test-infra
|
prow/pubsub/reporter/reporter.go
|
ShouldReport
|
func (c *Client) ShouldReport(pj *prowapi.ProwJob) bool {
pubSubMap := findLabels(pj, PubSubProjectLabel, PubSubTopicLabel)
return pubSubMap[PubSubProjectLabel] != "" && pubSubMap[PubSubTopicLabel] != ""
}
|
go
|
func (c *Client) ShouldReport(pj *prowapi.ProwJob) bool {
pubSubMap := findLabels(pj, PubSubProjectLabel, PubSubTopicLabel)
return pubSubMap[PubSubProjectLabel] != "" && pubSubMap[PubSubTopicLabel] != ""
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ShouldReport",
"(",
"pj",
"*",
"prowapi",
".",
"ProwJob",
")",
"bool",
"{",
"pubSubMap",
":=",
"findLabels",
"(",
"pj",
",",
"PubSubProjectLabel",
",",
"PubSubTopicLabel",
")",
"\n",
"return",
"pubSubMap",
"[",
"PubSubProjectLabel",
"]",
"!=",
"\"\"",
"&&",
"pubSubMap",
"[",
"PubSubTopicLabel",
"]",
"!=",
"\"\"",
"\n",
"}"
] |
// ShouldReport tells if a prowjob should be reported by this reporter
|
[
"ShouldReport",
"tells",
"if",
"a",
"prowjob",
"should",
"be",
"reported",
"by",
"this",
"reporter"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pubsub/reporter/reporter.go#L85-L88
|
test
|
kubernetes/test-infra
|
prow/gcsupload/run.go
|
Run
|
func (o Options) Run(spec *downwardapi.JobSpec, extra map[string]gcs.UploadFunc) error {
uploadTargets := o.assembleTargets(spec, extra)
if !o.DryRun {
ctx := context.Background()
gcsClient, err := storage.NewClient(ctx, option.WithCredentialsFile(o.GcsCredentialsFile))
if err != nil {
return fmt.Errorf("could not connect to GCS: %v", err)
}
if err := gcs.Upload(gcsClient.Bucket(o.Bucket), uploadTargets); err != nil {
return fmt.Errorf("failed to upload to GCS: %v", err)
}
} else {
for destination := range uploadTargets {
logrus.WithField("dest", destination).Info("Would upload")
}
}
logrus.Info("Finished upload to GCS")
return nil
}
|
go
|
func (o Options) Run(spec *downwardapi.JobSpec, extra map[string]gcs.UploadFunc) error {
uploadTargets := o.assembleTargets(spec, extra)
if !o.DryRun {
ctx := context.Background()
gcsClient, err := storage.NewClient(ctx, option.WithCredentialsFile(o.GcsCredentialsFile))
if err != nil {
return fmt.Errorf("could not connect to GCS: %v", err)
}
if err := gcs.Upload(gcsClient.Bucket(o.Bucket), uploadTargets); err != nil {
return fmt.Errorf("failed to upload to GCS: %v", err)
}
} else {
for destination := range uploadTargets {
logrus.WithField("dest", destination).Info("Would upload")
}
}
logrus.Info("Finished upload to GCS")
return nil
}
|
[
"func",
"(",
"o",
"Options",
")",
"Run",
"(",
"spec",
"*",
"downwardapi",
".",
"JobSpec",
",",
"extra",
"map",
"[",
"string",
"]",
"gcs",
".",
"UploadFunc",
")",
"error",
"{",
"uploadTargets",
":=",
"o",
".",
"assembleTargets",
"(",
"spec",
",",
"extra",
")",
"\n",
"if",
"!",
"o",
".",
"DryRun",
"{",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"gcsClient",
",",
"err",
":=",
"storage",
".",
"NewClient",
"(",
"ctx",
",",
"option",
".",
"WithCredentialsFile",
"(",
"o",
".",
"GcsCredentialsFile",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"could not connect to GCS: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"gcs",
".",
"Upload",
"(",
"gcsClient",
".",
"Bucket",
"(",
"o",
".",
"Bucket",
")",
",",
"uploadTargets",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to upload to GCS: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"for",
"destination",
":=",
"range",
"uploadTargets",
"{",
"logrus",
".",
"WithField",
"(",
"\"dest\"",
",",
"destination",
")",
".",
"Info",
"(",
"\"Would upload\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"logrus",
".",
"Info",
"(",
"\"Finished upload to GCS\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Run will upload files to GCS as prescribed by
// the options. Any extra files can be passed as
// a parameter and will have the prefix prepended
// to their destination in GCS, so the caller can
// operate relative to the base of the GCS dir.
|
[
"Run",
"will",
"upload",
"files",
"to",
"GCS",
"as",
"prescribed",
"by",
"the",
"options",
".",
"Any",
"extra",
"files",
"can",
"be",
"passed",
"as",
"a",
"parameter",
"and",
"will",
"have",
"the",
"prefix",
"prepended",
"to",
"their",
"destination",
"in",
"GCS",
"so",
"the",
"caller",
"can",
"operate",
"relative",
"to",
"the",
"base",
"of",
"the",
"GCS",
"dir",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/gcsupload/run.go#L41-L62
|
test
|
kubernetes/test-infra
|
prow/logrusutil/logrusutil.go
|
Format
|
func (d *DefaultFieldsFormatter) Format(entry *logrus.Entry) ([]byte, error) {
data := make(logrus.Fields, len(entry.Data)+len(d.DefaultFields))
for k, v := range d.DefaultFields {
data[k] = v
}
for k, v := range entry.Data {
data[k] = v
}
return d.WrappedFormatter.Format(&logrus.Entry{
Logger: entry.Logger,
Data: data,
Time: entry.Time,
Level: entry.Level,
Message: entry.Message,
})
}
|
go
|
func (d *DefaultFieldsFormatter) Format(entry *logrus.Entry) ([]byte, error) {
data := make(logrus.Fields, len(entry.Data)+len(d.DefaultFields))
for k, v := range d.DefaultFields {
data[k] = v
}
for k, v := range entry.Data {
data[k] = v
}
return d.WrappedFormatter.Format(&logrus.Entry{
Logger: entry.Logger,
Data: data,
Time: entry.Time,
Level: entry.Level,
Message: entry.Message,
})
}
|
[
"func",
"(",
"d",
"*",
"DefaultFieldsFormatter",
")",
"Format",
"(",
"entry",
"*",
"logrus",
".",
"Entry",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
":=",
"make",
"(",
"logrus",
".",
"Fields",
",",
"len",
"(",
"entry",
".",
"Data",
")",
"+",
"len",
"(",
"d",
".",
"DefaultFields",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"d",
".",
"DefaultFields",
"{",
"data",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"entry",
".",
"Data",
"{",
"data",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"d",
".",
"WrappedFormatter",
".",
"Format",
"(",
"&",
"logrus",
".",
"Entry",
"{",
"Logger",
":",
"entry",
".",
"Logger",
",",
"Data",
":",
"data",
",",
"Time",
":",
"entry",
".",
"Time",
",",
"Level",
":",
"entry",
".",
"Level",
",",
"Message",
":",
"entry",
".",
"Message",
",",
"}",
")",
"\n",
"}"
] |
// Format implements logrus.Formatter's Format. We allocate a new Fields
// map in order to not modify the caller's Entry, as that is not a thread
// safe operation.
|
[
"Format",
"implements",
"logrus",
".",
"Formatter",
"s",
"Format",
".",
"We",
"allocate",
"a",
"new",
"Fields",
"map",
"in",
"order",
"to",
"not",
"modify",
"the",
"caller",
"s",
"Entry",
"as",
"that",
"is",
"not",
"a",
"thread",
"safe",
"operation",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/logrusutil/logrusutil.go#L50-L65
|
test
|
kubernetes/test-infra
|
velodrome/sql/model.go
|
FindLabels
|
func (issue *Issue) FindLabels(regex *regexp.Regexp) []Label {
labels := []Label{}
for _, label := range issue.Labels {
if regex.MatchString(label.Name) {
labels = append(labels, label)
}
}
return labels
}
|
go
|
func (issue *Issue) FindLabels(regex *regexp.Regexp) []Label {
labels := []Label{}
for _, label := range issue.Labels {
if regex.MatchString(label.Name) {
labels = append(labels, label)
}
}
return labels
}
|
[
"func",
"(",
"issue",
"*",
"Issue",
")",
"FindLabels",
"(",
"regex",
"*",
"regexp",
".",
"Regexp",
")",
"[",
"]",
"Label",
"{",
"labels",
":=",
"[",
"]",
"Label",
"{",
"}",
"\n",
"for",
"_",
",",
"label",
":=",
"range",
"issue",
".",
"Labels",
"{",
"if",
"regex",
".",
"MatchString",
"(",
"label",
".",
"Name",
")",
"{",
"labels",
"=",
"append",
"(",
"labels",
",",
"label",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"labels",
"\n",
"}"
] |
// FindLabels returns the list of labels matching the regex
|
[
"FindLabels",
"returns",
"the",
"list",
"of",
"labels",
"matching",
"the",
"regex"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/velodrome/sql/model.go#L42-L52
|
test
|
kubernetes/test-infra
|
prow/initupload/options.go
|
AddFlags
|
func (o *Options) AddFlags(flags *flag.FlagSet) {
flags.StringVar(&o.Log, "clone-log", "", "Path to the clone records log")
o.Options.AddFlags(flags)
}
|
go
|
func (o *Options) AddFlags(flags *flag.FlagSet) {
flags.StringVar(&o.Log, "clone-log", "", "Path to the clone records log")
o.Options.AddFlags(flags)
}
|
[
"func",
"(",
"o",
"*",
"Options",
")",
"AddFlags",
"(",
"flags",
"*",
"flag",
".",
"FlagSet",
")",
"{",
"flags",
".",
"StringVar",
"(",
"&",
"o",
".",
"Log",
",",
"\"clone-log\"",
",",
"\"\"",
",",
"\"Path to the clone records log\"",
")",
"\n",
"o",
".",
"Options",
".",
"AddFlags",
"(",
"flags",
")",
"\n",
"}"
] |
// AddFlags binds flags to options.
|
[
"AddFlags",
"binds",
"flags",
"to",
"options",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/initupload/options.go#L59-L62
|
test
|
kubernetes/test-infra
|
prow/githuboauth/githuboauth.go
|
NewAgent
|
func NewAgent(config *config.GitHubOAuthConfig, logger *logrus.Entry) *Agent {
return &Agent{
gc: config,
logger: logger,
}
}
|
go
|
func NewAgent(config *config.GitHubOAuthConfig, logger *logrus.Entry) *Agent {
return &Agent{
gc: config,
logger: logger,
}
}
|
[
"func",
"NewAgent",
"(",
"config",
"*",
"config",
".",
"GitHubOAuthConfig",
",",
"logger",
"*",
"logrus",
".",
"Entry",
")",
"*",
"Agent",
"{",
"return",
"&",
"Agent",
"{",
"gc",
":",
"config",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"}"
] |
// NewAgent returns a new GitHub OAuth Agent.
|
[
"NewAgent",
"returns",
"a",
"new",
"GitHub",
"OAuth",
"Agent",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/githuboauth/githuboauth.go#L84-L89
|
test
|
kubernetes/test-infra
|
prow/githuboauth/githuboauth.go
|
HandleLogin
|
func (ga *Agent) HandleLogin(client OAuthClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
stateToken := xsrftoken.Generate(ga.gc.ClientSecret, "", "")
state := hex.EncodeToString([]byte(stateToken))
oauthSession, err := ga.gc.CookieStore.New(r, oauthSessionCookie)
oauthSession.Options.Secure = true
oauthSession.Options.HttpOnly = true
if err != nil {
ga.serverError(w, "Creating new OAuth session", err)
return
}
oauthSession.Options.MaxAge = 10 * 60
oauthSession.Values[stateKey] = state
if err := oauthSession.Save(r, w); err != nil {
ga.serverError(w, "Save oauth session", err)
return
}
redirectURL := client.AuthCodeURL(state, oauth2.ApprovalForce, oauth2.AccessTypeOnline)
http.Redirect(w, r, redirectURL, http.StatusFound)
}
}
|
go
|
func (ga *Agent) HandleLogin(client OAuthClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
stateToken := xsrftoken.Generate(ga.gc.ClientSecret, "", "")
state := hex.EncodeToString([]byte(stateToken))
oauthSession, err := ga.gc.CookieStore.New(r, oauthSessionCookie)
oauthSession.Options.Secure = true
oauthSession.Options.HttpOnly = true
if err != nil {
ga.serverError(w, "Creating new OAuth session", err)
return
}
oauthSession.Options.MaxAge = 10 * 60
oauthSession.Values[stateKey] = state
if err := oauthSession.Save(r, w); err != nil {
ga.serverError(w, "Save oauth session", err)
return
}
redirectURL := client.AuthCodeURL(state, oauth2.ApprovalForce, oauth2.AccessTypeOnline)
http.Redirect(w, r, redirectURL, http.StatusFound)
}
}
|
[
"func",
"(",
"ga",
"*",
"Agent",
")",
"HandleLogin",
"(",
"client",
"OAuthClient",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"stateToken",
":=",
"xsrftoken",
".",
"Generate",
"(",
"ga",
".",
"gc",
".",
"ClientSecret",
",",
"\"\"",
",",
"\"\"",
")",
"\n",
"state",
":=",
"hex",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"stateToken",
")",
")",
"\n",
"oauthSession",
",",
"err",
":=",
"ga",
".",
"gc",
".",
"CookieStore",
".",
"New",
"(",
"r",
",",
"oauthSessionCookie",
")",
"\n",
"oauthSession",
".",
"Options",
".",
"Secure",
"=",
"true",
"\n",
"oauthSession",
".",
"Options",
".",
"HttpOnly",
"=",
"true",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ga",
".",
"serverError",
"(",
"w",
",",
"\"Creating new OAuth session\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"oauthSession",
".",
"Options",
".",
"MaxAge",
"=",
"10",
"*",
"60",
"\n",
"oauthSession",
".",
"Values",
"[",
"stateKey",
"]",
"=",
"state",
"\n",
"if",
"err",
":=",
"oauthSession",
".",
"Save",
"(",
"r",
",",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"ga",
".",
"serverError",
"(",
"w",
",",
"\"Save oauth session\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"redirectURL",
":=",
"client",
".",
"AuthCodeURL",
"(",
"state",
",",
"oauth2",
".",
"ApprovalForce",
",",
"oauth2",
".",
"AccessTypeOnline",
")",
"\n",
"http",
".",
"Redirect",
"(",
"w",
",",
"r",
",",
"redirectURL",
",",
"http",
".",
"StatusFound",
")",
"\n",
"}",
"\n",
"}"
] |
// HandleLogin handles GitHub login request from front-end. It starts a new git oauth session and
// redirect user to GitHub OAuth end-point for authentication.
|
[
"HandleLogin",
"handles",
"GitHub",
"login",
"request",
"from",
"front",
"-",
"end",
".",
"It",
"starts",
"a",
"new",
"git",
"oauth",
"session",
"and",
"redirect",
"user",
"to",
"GitHub",
"OAuth",
"end",
"-",
"point",
"for",
"authentication",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/githuboauth/githuboauth.go#L93-L115
|
test
|
kubernetes/test-infra
|
prow/githuboauth/githuboauth.go
|
HandleLogout
|
func (ga *Agent) HandleLogout(client OAuthClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
accessTokenSession, err := ga.gc.CookieStore.Get(r, tokenSession)
if err != nil {
ga.serverError(w, "get cookie", err)
return
}
// Clear session
accessTokenSession.Options.MaxAge = -1
if err := accessTokenSession.Save(r, w); err != nil {
ga.serverError(w, "Save invalidated session on log out", err)
return
}
loginCookie, err := r.Cookie(loginSession)
if err == nil {
loginCookie.MaxAge = -1
loginCookie.Expires = time.Now().Add(-time.Hour * 24)
http.SetCookie(w, loginCookie)
}
http.Redirect(w, r, ga.gc.FinalRedirectURL, http.StatusFound)
}
}
|
go
|
func (ga *Agent) HandleLogout(client OAuthClient) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
accessTokenSession, err := ga.gc.CookieStore.Get(r, tokenSession)
if err != nil {
ga.serverError(w, "get cookie", err)
return
}
// Clear session
accessTokenSession.Options.MaxAge = -1
if err := accessTokenSession.Save(r, w); err != nil {
ga.serverError(w, "Save invalidated session on log out", err)
return
}
loginCookie, err := r.Cookie(loginSession)
if err == nil {
loginCookie.MaxAge = -1
loginCookie.Expires = time.Now().Add(-time.Hour * 24)
http.SetCookie(w, loginCookie)
}
http.Redirect(w, r, ga.gc.FinalRedirectURL, http.StatusFound)
}
}
|
[
"func",
"(",
"ga",
"*",
"Agent",
")",
"HandleLogout",
"(",
"client",
"OAuthClient",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"accessTokenSession",
",",
"err",
":=",
"ga",
".",
"gc",
".",
"CookieStore",
".",
"Get",
"(",
"r",
",",
"tokenSession",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ga",
".",
"serverError",
"(",
"w",
",",
"\"get cookie\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"accessTokenSession",
".",
"Options",
".",
"MaxAge",
"=",
"-",
"1",
"\n",
"if",
"err",
":=",
"accessTokenSession",
".",
"Save",
"(",
"r",
",",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"ga",
".",
"serverError",
"(",
"w",
",",
"\"Save invalidated session on log out\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"loginCookie",
",",
"err",
":=",
"r",
".",
"Cookie",
"(",
"loginSession",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"loginCookie",
".",
"MaxAge",
"=",
"-",
"1",
"\n",
"loginCookie",
".",
"Expires",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"-",
"time",
".",
"Hour",
"*",
"24",
")",
"\n",
"http",
".",
"SetCookie",
"(",
"w",
",",
"loginCookie",
")",
"\n",
"}",
"\n",
"http",
".",
"Redirect",
"(",
"w",
",",
"r",
",",
"ga",
".",
"gc",
".",
"FinalRedirectURL",
",",
"http",
".",
"StatusFound",
")",
"\n",
"}",
"\n",
"}"
] |
// HandleLogout handles GitHub logout request from front-end. It invalidates cookie sessions and
// redirect back to the front page.
|
[
"HandleLogout",
"handles",
"GitHub",
"logout",
"request",
"from",
"front",
"-",
"end",
".",
"It",
"invalidates",
"cookie",
"sessions",
"and",
"redirect",
"back",
"to",
"the",
"front",
"page",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/githuboauth/githuboauth.go#L119-L140
|
test
|
kubernetes/test-infra
|
prow/githuboauth/githuboauth.go
|
serverError
|
func (ga *Agent) serverError(w http.ResponseWriter, action string, err error) {
ga.logger.WithError(err).Errorf("Error %s.", action)
msg := fmt.Sprintf("500 Internal server error %s: %v", action, err)
http.Error(w, msg, http.StatusInternalServerError)
}
|
go
|
func (ga *Agent) serverError(w http.ResponseWriter, action string, err error) {
ga.logger.WithError(err).Errorf("Error %s.", action)
msg := fmt.Sprintf("500 Internal server error %s: %v", action, err)
http.Error(w, msg, http.StatusInternalServerError)
}
|
[
"func",
"(",
"ga",
"*",
"Agent",
")",
"serverError",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"action",
"string",
",",
"err",
"error",
")",
"{",
"ga",
".",
"logger",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"Error %s.\"",
",",
"action",
")",
"\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"500 Internal server error %s: %v\"",
",",
"action",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"msg",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}"
] |
// Handles server errors.
|
[
"Handles",
"server",
"errors",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/githuboauth/githuboauth.go#L227-L231
|
test
|
kubernetes/test-infra
|
boskos/crds/resources_config_crd.go
|
FromItem
|
func (in *ResourcesConfigObject) FromItem(i common.Item) {
c, err := common.ItemToResourcesConfig(i)
if err == nil {
in.fromConfig(c)
}
}
|
go
|
func (in *ResourcesConfigObject) FromItem(i common.Item) {
c, err := common.ItemToResourcesConfig(i)
if err == nil {
in.fromConfig(c)
}
}
|
[
"func",
"(",
"in",
"*",
"ResourcesConfigObject",
")",
"FromItem",
"(",
"i",
"common",
".",
"Item",
")",
"{",
"c",
",",
"err",
":=",
"common",
".",
"ItemToResourcesConfig",
"(",
"i",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"in",
".",
"fromConfig",
"(",
"c",
")",
"\n",
"}",
"\n",
"}"
] |
// FromItem implements the Object interface
|
[
"FromItem",
"implements",
"the",
"Object",
"interface"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/resources_config_crd.go#L116-L121
|
test
|
kubernetes/test-infra
|
boskos/crds/resources_config_crd.go
|
GetItems
|
func (in *ResourcesConfigCollection) GetItems() []Object {
var items []Object
for _, i := range in.Items {
items = append(items, i)
}
return items
}
|
go
|
func (in *ResourcesConfigCollection) GetItems() []Object {
var items []Object
for _, i := range in.Items {
items = append(items, i)
}
return items
}
|
[
"func",
"(",
"in",
"*",
"ResourcesConfigCollection",
")",
"GetItems",
"(",
")",
"[",
"]",
"Object",
"{",
"var",
"items",
"[",
"]",
"Object",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"in",
".",
"Items",
"{",
"items",
"=",
"append",
"(",
"items",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"items",
"\n",
"}"
] |
// GetItems implements the Collection interface
|
[
"GetItems",
"implements",
"the",
"Collection",
"interface"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/resources_config_crd.go#L124-L130
|
test
|
kubernetes/test-infra
|
boskos/crds/resources_config_crd.go
|
SetItems
|
func (in *ResourcesConfigCollection) SetItems(objects []Object) {
var items []*ResourcesConfigObject
for _, b := range objects {
items = append(items, b.(*ResourcesConfigObject))
}
in.Items = items
}
|
go
|
func (in *ResourcesConfigCollection) SetItems(objects []Object) {
var items []*ResourcesConfigObject
for _, b := range objects {
items = append(items, b.(*ResourcesConfigObject))
}
in.Items = items
}
|
[
"func",
"(",
"in",
"*",
"ResourcesConfigCollection",
")",
"SetItems",
"(",
"objects",
"[",
"]",
"Object",
")",
"{",
"var",
"items",
"[",
"]",
"*",
"ResourcesConfigObject",
"\n",
"for",
"_",
",",
"b",
":=",
"range",
"objects",
"{",
"items",
"=",
"append",
"(",
"items",
",",
"b",
".",
"(",
"*",
"ResourcesConfigObject",
")",
")",
"\n",
"}",
"\n",
"in",
".",
"Items",
"=",
"items",
"\n",
"}"
] |
// SetItems implements the Collection interface
|
[
"SetItems",
"implements",
"the",
"Collection",
"interface"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/resources_config_crd.go#L133-L139
|
test
|
kubernetes/test-infra
|
prow/github/types.go
|
UnmarshalText
|
func (l *RepoPermissionLevel) UnmarshalText(text []byte) error {
v := RepoPermissionLevel(text)
if _, ok := repoPermissionLevels[v]; !ok {
return fmt.Errorf("bad repo permission: %s not in %v", v, repoPermissionLevels)
}
*l = v
return nil
}
|
go
|
func (l *RepoPermissionLevel) UnmarshalText(text []byte) error {
v := RepoPermissionLevel(text)
if _, ok := repoPermissionLevels[v]; !ok {
return fmt.Errorf("bad repo permission: %s not in %v", v, repoPermissionLevels)
}
*l = v
return nil
}
|
[
"func",
"(",
"l",
"*",
"RepoPermissionLevel",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"v",
":=",
"RepoPermissionLevel",
"(",
"text",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"repoPermissionLevels",
"[",
"v",
"]",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"bad repo permission: %s not in %v\"",
",",
"v",
",",
"repoPermissionLevels",
")",
"\n",
"}",
"\n",
"*",
"l",
"=",
"v",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalText validates the text is a valid string
|
[
"UnmarshalText",
"validates",
"the",
"text",
"is",
"a",
"valid",
"string"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/types.go#L342-L349
|
test
|
kubernetes/test-infra
|
prow/github/types.go
|
IsAssignee
|
func (i Issue) IsAssignee(login string) bool {
for _, assignee := range i.Assignees {
if NormLogin(login) == NormLogin(assignee.Login) {
return true
}
}
return false
}
|
go
|
func (i Issue) IsAssignee(login string) bool {
for _, assignee := range i.Assignees {
if NormLogin(login) == NormLogin(assignee.Login) {
return true
}
}
return false
}
|
[
"func",
"(",
"i",
"Issue",
")",
"IsAssignee",
"(",
"login",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"assignee",
":=",
"range",
"i",
".",
"Assignees",
"{",
"if",
"NormLogin",
"(",
"login",
")",
"==",
"NormLogin",
"(",
"assignee",
".",
"Login",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// IsAssignee checks if a user is assigned to the issue.
|
[
"IsAssignee",
"checks",
"if",
"a",
"user",
"is",
"assigned",
"to",
"the",
"issue",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/types.go#L529-L536
|
test
|
kubernetes/test-infra
|
prow/github/types.go
|
IsAuthor
|
func (i Issue) IsAuthor(login string) bool {
return NormLogin(i.User.Login) == NormLogin(login)
}
|
go
|
func (i Issue) IsAuthor(login string) bool {
return NormLogin(i.User.Login) == NormLogin(login)
}
|
[
"func",
"(",
"i",
"Issue",
")",
"IsAuthor",
"(",
"login",
"string",
")",
"bool",
"{",
"return",
"NormLogin",
"(",
"i",
".",
"User",
".",
"Login",
")",
"==",
"NormLogin",
"(",
"login",
")",
"\n",
"}"
] |
// IsAuthor checks if a user is the author of the issue.
|
[
"IsAuthor",
"checks",
"if",
"a",
"user",
"is",
"the",
"author",
"of",
"the",
"issue",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/types.go#L539-L541
|
test
|
kubernetes/test-infra
|
prow/github/types.go
|
HasLabel
|
func (i Issue) HasLabel(labelToFind string) bool {
for _, label := range i.Labels {
if strings.ToLower(label.Name) == strings.ToLower(labelToFind) {
return true
}
}
return false
}
|
go
|
func (i Issue) HasLabel(labelToFind string) bool {
for _, label := range i.Labels {
if strings.ToLower(label.Name) == strings.ToLower(labelToFind) {
return true
}
}
return false
}
|
[
"func",
"(",
"i",
"Issue",
")",
"HasLabel",
"(",
"labelToFind",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"label",
":=",
"range",
"i",
".",
"Labels",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"label",
".",
"Name",
")",
"==",
"strings",
".",
"ToLower",
"(",
"labelToFind",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// HasLabel checks if an issue has a given label.
|
[
"HasLabel",
"checks",
"if",
"an",
"issue",
"has",
"a",
"given",
"label",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/types.go#L549-L556
|
test
|
kubernetes/test-infra
|
prow/github/types.go
|
Branch
|
func (pe PushEvent) Branch() string {
ref := strings.TrimPrefix(pe.Ref, "refs/heads/") // if Ref is a branch
ref = strings.TrimPrefix(ref, "refs/tags/") // if Ref is a tag
return ref
}
|
go
|
func (pe PushEvent) Branch() string {
ref := strings.TrimPrefix(pe.Ref, "refs/heads/") // if Ref is a branch
ref = strings.TrimPrefix(ref, "refs/tags/") // if Ref is a tag
return ref
}
|
[
"func",
"(",
"pe",
"PushEvent",
")",
"Branch",
"(",
")",
"string",
"{",
"ref",
":=",
"strings",
".",
"TrimPrefix",
"(",
"pe",
".",
"Ref",
",",
"\"refs/heads/\"",
")",
"\n",
"ref",
"=",
"strings",
".",
"TrimPrefix",
"(",
"ref",
",",
"\"refs/tags/\"",
")",
"\n",
"return",
"ref",
"\n",
"}"
] |
// Branch returns the name of the branch to which the user pushed.
|
[
"Branch",
"returns",
"the",
"name",
"of",
"the",
"branch",
"to",
"which",
"the",
"user",
"pushed",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/types.go#L613-L617
|
test
|
kubernetes/test-infra
|
prow/github/report/report.go
|
truncate
|
func truncate(in string) string {
const (
half = (maxLen - len(elide)) / 2
)
if len(in) <= maxLen {
return in
}
return in[:half] + elide + in[len(in)-half:]
}
|
go
|
func truncate(in string) string {
const (
half = (maxLen - len(elide)) / 2
)
if len(in) <= maxLen {
return in
}
return in[:half] + elide + in[len(in)-half:]
}
|
[
"func",
"truncate",
"(",
"in",
"string",
")",
"string",
"{",
"const",
"(",
"half",
"=",
"(",
"maxLen",
"-",
"len",
"(",
"elide",
")",
")",
"/",
"2",
"\n",
")",
"\n",
"if",
"len",
"(",
"in",
")",
"<=",
"maxLen",
"{",
"return",
"in",
"\n",
"}",
"\n",
"return",
"in",
"[",
":",
"half",
"]",
"+",
"elide",
"+",
"in",
"[",
"len",
"(",
"in",
")",
"-",
"half",
":",
"]",
"\n",
"}"
] |
// truncate converts "really long messages" into "really ... messages".
|
[
"truncate",
"converts",
"really",
"long",
"messages",
"into",
"really",
"...",
"messages",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/report/report.go#L74-L82
|
test
|
kubernetes/test-infra
|
prow/github/report/report.go
|
reportStatus
|
func reportStatus(ghc GitHubClient, pj prowapi.ProwJob) error {
refs := pj.Spec.Refs
if pj.Spec.Report {
contextState, err := prowjobStateToGitHubStatus(pj.Status.State)
if err != nil {
return err
}
sha := refs.BaseSHA
if len(refs.Pulls) > 0 {
sha = refs.Pulls[0].SHA
}
if err := ghc.CreateStatus(refs.Org, refs.Repo, sha, github.Status{
State: contextState,
Description: truncate(pj.Status.Description),
Context: pj.Spec.Context, // consider truncating this too
TargetURL: pj.Status.URL,
}); err != nil {
return err
}
}
return nil
}
|
go
|
func reportStatus(ghc GitHubClient, pj prowapi.ProwJob) error {
refs := pj.Spec.Refs
if pj.Spec.Report {
contextState, err := prowjobStateToGitHubStatus(pj.Status.State)
if err != nil {
return err
}
sha := refs.BaseSHA
if len(refs.Pulls) > 0 {
sha = refs.Pulls[0].SHA
}
if err := ghc.CreateStatus(refs.Org, refs.Repo, sha, github.Status{
State: contextState,
Description: truncate(pj.Status.Description),
Context: pj.Spec.Context, // consider truncating this too
TargetURL: pj.Status.URL,
}); err != nil {
return err
}
}
return nil
}
|
[
"func",
"reportStatus",
"(",
"ghc",
"GitHubClient",
",",
"pj",
"prowapi",
".",
"ProwJob",
")",
"error",
"{",
"refs",
":=",
"pj",
".",
"Spec",
".",
"Refs",
"\n",
"if",
"pj",
".",
"Spec",
".",
"Report",
"{",
"contextState",
",",
"err",
":=",
"prowjobStateToGitHubStatus",
"(",
"pj",
".",
"Status",
".",
"State",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sha",
":=",
"refs",
".",
"BaseSHA",
"\n",
"if",
"len",
"(",
"refs",
".",
"Pulls",
")",
">",
"0",
"{",
"sha",
"=",
"refs",
".",
"Pulls",
"[",
"0",
"]",
".",
"SHA",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ghc",
".",
"CreateStatus",
"(",
"refs",
".",
"Org",
",",
"refs",
".",
"Repo",
",",
"sha",
",",
"github",
".",
"Status",
"{",
"State",
":",
"contextState",
",",
"Description",
":",
"truncate",
"(",
"pj",
".",
"Status",
".",
"Description",
")",
",",
"Context",
":",
"pj",
".",
"Spec",
".",
"Context",
",",
"TargetURL",
":",
"pj",
".",
"Status",
".",
"URL",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// reportStatus should be called on any prowjob status changes
|
[
"reportStatus",
"should",
"be",
"called",
"on",
"any",
"prowjob",
"status",
"changes"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/report/report.go#L85-L106
|
test
|
kubernetes/test-infra
|
prow/github/report/report.go
|
parseIssueComments
|
func parseIssueComments(pj prowapi.ProwJob, botName string, ics []github.IssueComment) ([]int, []string, int) {
var delete []int
var previousComments []int
var latestComment int
var entries []string
// First accumulate result entries and comment IDs
for _, ic := range ics {
if ic.User.Login != botName {
continue
}
// Old report comments started with the context. Delete them.
// TODO(spxtr): Delete this check a few weeks after this merges.
if strings.HasPrefix(ic.Body, pj.Spec.Context) {
delete = append(delete, ic.ID)
}
if !strings.Contains(ic.Body, commentTag) {
continue
}
if latestComment != 0 {
previousComments = append(previousComments, latestComment)
}
latestComment = ic.ID
var tracking bool
for _, line := range strings.Split(ic.Body, "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "---") {
tracking = true
} else if len(line) == 0 {
tracking = false
} else if tracking {
entries = append(entries, line)
}
}
}
var newEntries []string
// Next decide which entries to keep.
for i := range entries {
keep := true
f1 := strings.Split(entries[i], " | ")
for j := range entries {
if i == j {
continue
}
f2 := strings.Split(entries[j], " | ")
// Use the newer results if there are multiple.
if j > i && f2[0] == f1[0] {
keep = false
}
}
// Use the current result if there is an old one.
if pj.Spec.Context == f1[0] {
keep = false
}
if keep {
newEntries = append(newEntries, entries[i])
}
}
var createNewComment bool
if string(pj.Status.State) == github.StatusFailure {
newEntries = append(newEntries, createEntry(pj))
createNewComment = true
}
delete = append(delete, previousComments...)
if (createNewComment || len(newEntries) == 0) && latestComment != 0 {
delete = append(delete, latestComment)
latestComment = 0
}
return delete, newEntries, latestComment
}
|
go
|
func parseIssueComments(pj prowapi.ProwJob, botName string, ics []github.IssueComment) ([]int, []string, int) {
var delete []int
var previousComments []int
var latestComment int
var entries []string
// First accumulate result entries and comment IDs
for _, ic := range ics {
if ic.User.Login != botName {
continue
}
// Old report comments started with the context. Delete them.
// TODO(spxtr): Delete this check a few weeks after this merges.
if strings.HasPrefix(ic.Body, pj.Spec.Context) {
delete = append(delete, ic.ID)
}
if !strings.Contains(ic.Body, commentTag) {
continue
}
if latestComment != 0 {
previousComments = append(previousComments, latestComment)
}
latestComment = ic.ID
var tracking bool
for _, line := range strings.Split(ic.Body, "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "---") {
tracking = true
} else if len(line) == 0 {
tracking = false
} else if tracking {
entries = append(entries, line)
}
}
}
var newEntries []string
// Next decide which entries to keep.
for i := range entries {
keep := true
f1 := strings.Split(entries[i], " | ")
for j := range entries {
if i == j {
continue
}
f2 := strings.Split(entries[j], " | ")
// Use the newer results if there are multiple.
if j > i && f2[0] == f1[0] {
keep = false
}
}
// Use the current result if there is an old one.
if pj.Spec.Context == f1[0] {
keep = false
}
if keep {
newEntries = append(newEntries, entries[i])
}
}
var createNewComment bool
if string(pj.Status.State) == github.StatusFailure {
newEntries = append(newEntries, createEntry(pj))
createNewComment = true
}
delete = append(delete, previousComments...)
if (createNewComment || len(newEntries) == 0) && latestComment != 0 {
delete = append(delete, latestComment)
latestComment = 0
}
return delete, newEntries, latestComment
}
|
[
"func",
"parseIssueComments",
"(",
"pj",
"prowapi",
".",
"ProwJob",
",",
"botName",
"string",
",",
"ics",
"[",
"]",
"github",
".",
"IssueComment",
")",
"(",
"[",
"]",
"int",
",",
"[",
"]",
"string",
",",
"int",
")",
"{",
"var",
"delete",
"[",
"]",
"int",
"\n",
"var",
"previousComments",
"[",
"]",
"int",
"\n",
"var",
"latestComment",
"int",
"\n",
"var",
"entries",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"ic",
":=",
"range",
"ics",
"{",
"if",
"ic",
".",
"User",
".",
"Login",
"!=",
"botName",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"ic",
".",
"Body",
",",
"pj",
".",
"Spec",
".",
"Context",
")",
"{",
"delete",
"=",
"append",
"(",
"delete",
",",
"ic",
".",
"ID",
")",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"Contains",
"(",
"ic",
".",
"Body",
",",
"commentTag",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"latestComment",
"!=",
"0",
"{",
"previousComments",
"=",
"append",
"(",
"previousComments",
",",
"latestComment",
")",
"\n",
"}",
"\n",
"latestComment",
"=",
"ic",
".",
"ID",
"\n",
"var",
"tracking",
"bool",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"ic",
".",
"Body",
",",
"\"\\n\"",
")",
"\\n",
"\n",
"}",
"\n",
"{",
"line",
"=",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"line",
",",
"\"---\"",
")",
"{",
"tracking",
"=",
"true",
"\n",
"}",
"else",
"if",
"len",
"(",
"line",
")",
"==",
"0",
"{",
"tracking",
"=",
"false",
"\n",
"}",
"else",
"if",
"tracking",
"{",
"entries",
"=",
"append",
"(",
"entries",
",",
"line",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"newEntries",
"[",
"]",
"string",
"\n",
"for",
"i",
":=",
"range",
"entries",
"{",
"keep",
":=",
"true",
"\n",
"f1",
":=",
"strings",
".",
"Split",
"(",
"entries",
"[",
"i",
"]",
",",
"\" | \"",
")",
"\n",
"for",
"j",
":=",
"range",
"entries",
"{",
"if",
"i",
"==",
"j",
"{",
"continue",
"\n",
"}",
"\n",
"f2",
":=",
"strings",
".",
"Split",
"(",
"entries",
"[",
"j",
"]",
",",
"\" | \"",
")",
"\n",
"if",
"j",
">",
"i",
"&&",
"f2",
"[",
"0",
"]",
"==",
"f1",
"[",
"0",
"]",
"{",
"keep",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"pj",
".",
"Spec",
".",
"Context",
"==",
"f1",
"[",
"0",
"]",
"{",
"keep",
"=",
"false",
"\n",
"}",
"\n",
"if",
"keep",
"{",
"newEntries",
"=",
"append",
"(",
"newEntries",
",",
"entries",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"createNewComment",
"bool",
"\n",
"if",
"string",
"(",
"pj",
".",
"Status",
".",
"State",
")",
"==",
"github",
".",
"StatusFailure",
"{",
"newEntries",
"=",
"append",
"(",
"newEntries",
",",
"createEntry",
"(",
"pj",
")",
")",
"\n",
"createNewComment",
"=",
"true",
"\n",
"}",
"\n",
"delete",
"=",
"append",
"(",
"delete",
",",
"previousComments",
"...",
")",
"\n",
"if",
"(",
"createNewComment",
"||",
"len",
"(",
"newEntries",
")",
"==",
"0",
")",
"&&",
"latestComment",
"!=",
"0",
"{",
"delete",
"=",
"append",
"(",
"delete",
",",
"latestComment",
")",
"\n",
"latestComment",
"=",
"0",
"\n",
"}",
"\n",
"}"
] |
// parseIssueComments returns a list of comments to delete, a list of table
// entries, and the ID of the comment to update. If there are no table entries
// then don't make a new comment. Otherwise, if the comment to update is 0,
// create a new comment.
|
[
"parseIssueComments",
"returns",
"a",
"list",
"of",
"comments",
"to",
"delete",
"a",
"list",
"of",
"table",
"entries",
"and",
"the",
"ID",
"of",
"the",
"comment",
"to",
"update",
".",
"If",
"there",
"are",
"no",
"table",
"entries",
"then",
"don",
"t",
"make",
"a",
"new",
"comment",
".",
"Otherwise",
"if",
"the",
"comment",
"to",
"update",
"is",
"0",
"create",
"a",
"new",
"comment",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/report/report.go#L196-L264
|
test
|
kubernetes/test-infra
|
prow/github/report/report.go
|
createComment
|
func createComment(reportTemplate *template.Template, pj prowapi.ProwJob, entries []string) (string, error) {
plural := ""
if len(entries) > 1 {
plural = "s"
}
var b bytes.Buffer
if reportTemplate != nil {
if err := reportTemplate.Execute(&b, &pj); err != nil {
return "", err
}
}
lines := []string{
fmt.Sprintf("@%s: The following test%s **failed**, say `/retest` to rerun them all:", pj.Spec.Refs.Pulls[0].Author, plural),
"",
"Test name | Commit | Details | Rerun command",
"--- | --- | --- | ---",
}
lines = append(lines, entries...)
if reportTemplate != nil {
lines = append(lines, "", b.String())
}
lines = append(lines, []string{
"",
"<details>",
"",
plugins.AboutThisBot,
"</details>",
commentTag,
}...)
return strings.Join(lines, "\n"), nil
}
|
go
|
func createComment(reportTemplate *template.Template, pj prowapi.ProwJob, entries []string) (string, error) {
plural := ""
if len(entries) > 1 {
plural = "s"
}
var b bytes.Buffer
if reportTemplate != nil {
if err := reportTemplate.Execute(&b, &pj); err != nil {
return "", err
}
}
lines := []string{
fmt.Sprintf("@%s: The following test%s **failed**, say `/retest` to rerun them all:", pj.Spec.Refs.Pulls[0].Author, plural),
"",
"Test name | Commit | Details | Rerun command",
"--- | --- | --- | ---",
}
lines = append(lines, entries...)
if reportTemplate != nil {
lines = append(lines, "", b.String())
}
lines = append(lines, []string{
"",
"<details>",
"",
plugins.AboutThisBot,
"</details>",
commentTag,
}...)
return strings.Join(lines, "\n"), nil
}
|
[
"func",
"createComment",
"(",
"reportTemplate",
"*",
"template",
".",
"Template",
",",
"pj",
"prowapi",
".",
"ProwJob",
",",
"entries",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"plural",
":=",
"\"\"",
"\n",
"if",
"len",
"(",
"entries",
")",
">",
"1",
"{",
"plural",
"=",
"\"s\"",
"\n",
"}",
"\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"if",
"reportTemplate",
"!=",
"nil",
"{",
"if",
"err",
":=",
"reportTemplate",
".",
"Execute",
"(",
"&",
"b",
",",
"&",
"pj",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"lines",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"@%s: The following test%s **failed**, say `/retest` to rerun them all:\"",
",",
"pj",
".",
"Spec",
".",
"Refs",
".",
"Pulls",
"[",
"0",
"]",
".",
"Author",
",",
"plural",
")",
",",
"\"\"",
",",
"\"Test name | Commit | Details | Rerun command\"",
",",
"\"--- | --- | --- | ---\"",
",",
"}",
"\n",
"lines",
"=",
"append",
"(",
"lines",
",",
"entries",
"...",
")",
"\n",
"if",
"reportTemplate",
"!=",
"nil",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"\"\"",
",",
"b",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"lines",
"=",
"append",
"(",
"lines",
",",
"[",
"]",
"string",
"{",
"\"\"",
",",
"\"<details>\"",
",",
"\"\"",
",",
"plugins",
".",
"AboutThisBot",
",",
"\"</details>\"",
",",
"commentTag",
",",
"}",
"...",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"lines",
",",
"\"\\n\"",
")",
",",
"nil",
"\n",
"}"
] |
// createComment take a ProwJob and a list of entries generated with
// createEntry and returns a nicely formatted comment. It may fail if template
// execution fails.
|
[
"createComment",
"take",
"a",
"ProwJob",
"and",
"a",
"list",
"of",
"entries",
"generated",
"with",
"createEntry",
"and",
"returns",
"a",
"nicely",
"formatted",
"comment",
".",
"It",
"may",
"fail",
"if",
"template",
"execution",
"fails",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/report/report.go#L278-L308
|
test
|
kubernetes/test-infra
|
prow/spyglass/lenses/junit/lens.go
|
Config
|
func (lens Lens) Config() lenses.LensConfig {
return lenses.LensConfig{
Name: name,
Title: title,
Priority: priority,
}
}
|
go
|
func (lens Lens) Config() lenses.LensConfig {
return lenses.LensConfig{
Name: name,
Title: title,
Priority: priority,
}
}
|
[
"func",
"(",
"lens",
"Lens",
")",
"Config",
"(",
")",
"lenses",
".",
"LensConfig",
"{",
"return",
"lenses",
".",
"LensConfig",
"{",
"Name",
":",
"name",
",",
"Title",
":",
"title",
",",
"Priority",
":",
"priority",
",",
"}",
"\n",
"}"
] |
// Config returns the lens's configuration.
|
[
"Config",
"returns",
"the",
"lens",
"s",
"configuration",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/lenses/junit/lens.go#L48-L54
|
test
|
kubernetes/test-infra
|
prow/spyglass/lenses/junit/lens.go
|
Callback
|
func (lens Lens) Callback(artifacts []lenses.Artifact, resourceDir string, data string) string {
return ""
}
|
go
|
func (lens Lens) Callback(artifacts []lenses.Artifact, resourceDir string, data string) string {
return ""
}
|
[
"func",
"(",
"lens",
"Lens",
")",
"Callback",
"(",
"artifacts",
"[",
"]",
"lenses",
".",
"Artifact",
",",
"resourceDir",
"string",
",",
"data",
"string",
")",
"string",
"{",
"return",
"\"\"",
"\n",
"}"
] |
// Callback does nothing.
|
[
"Callback",
"does",
"nothing",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/lenses/junit/lens.go#L70-L72
|
test
|
kubernetes/test-infra
|
prow/pod-utils/clone/format.go
|
FormatRecord
|
func FormatRecord(record Record) string {
output := bytes.Buffer{}
if record.Failed {
fmt.Fprintln(&output, "# FAILED!")
}
fmt.Fprintf(&output, "# Cloning %s/%s at %s", record.Refs.Org, record.Refs.Repo, record.Refs.BaseRef)
if record.Refs.BaseSHA != "" {
fmt.Fprintf(&output, "(%s)", record.Refs.BaseSHA)
}
output.WriteString("\n")
if len(record.Refs.Pulls) > 0 {
output.WriteString("# Checking out pulls:\n")
for _, pull := range record.Refs.Pulls {
fmt.Fprintf(&output, "#\t%d", pull.Number)
if pull.SHA != "" {
fmt.Fprintf(&output, "(%s)", pull.SHA)
}
fmt.Fprint(&output, "\n")
}
}
for _, command := range record.Commands {
fmt.Fprintf(&output, "$ %s\n", command.Command)
fmt.Fprint(&output, command.Output)
if command.Error != "" {
fmt.Fprintf(&output, "# Error: %s\n", command.Error)
}
}
return output.String()
}
|
go
|
func FormatRecord(record Record) string {
output := bytes.Buffer{}
if record.Failed {
fmt.Fprintln(&output, "# FAILED!")
}
fmt.Fprintf(&output, "# Cloning %s/%s at %s", record.Refs.Org, record.Refs.Repo, record.Refs.BaseRef)
if record.Refs.BaseSHA != "" {
fmt.Fprintf(&output, "(%s)", record.Refs.BaseSHA)
}
output.WriteString("\n")
if len(record.Refs.Pulls) > 0 {
output.WriteString("# Checking out pulls:\n")
for _, pull := range record.Refs.Pulls {
fmt.Fprintf(&output, "#\t%d", pull.Number)
if pull.SHA != "" {
fmt.Fprintf(&output, "(%s)", pull.SHA)
}
fmt.Fprint(&output, "\n")
}
}
for _, command := range record.Commands {
fmt.Fprintf(&output, "$ %s\n", command.Command)
fmt.Fprint(&output, command.Output)
if command.Error != "" {
fmt.Fprintf(&output, "# Error: %s\n", command.Error)
}
}
return output.String()
}
|
[
"func",
"FormatRecord",
"(",
"record",
"Record",
")",
"string",
"{",
"output",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"if",
"record",
".",
"Failed",
"{",
"fmt",
".",
"Fprintln",
"(",
"&",
"output",
",",
"\"# FAILED!\"",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"&",
"output",
",",
"\"# Cloning %s/%s at %s\"",
",",
"record",
".",
"Refs",
".",
"Org",
",",
"record",
".",
"Refs",
".",
"Repo",
",",
"record",
".",
"Refs",
".",
"BaseRef",
")",
"\n",
"if",
"record",
".",
"Refs",
".",
"BaseSHA",
"!=",
"\"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"output",
",",
"\"(%s)\"",
",",
"record",
".",
"Refs",
".",
"BaseSHA",
")",
"\n",
"}",
"\n",
"output",
".",
"WriteString",
"(",
"\"\\n\"",
")",
"\n",
"\\n",
"\n",
"if",
"len",
"(",
"record",
".",
"Refs",
".",
"Pulls",
")",
">",
"0",
"{",
"output",
".",
"WriteString",
"(",
"\"# Checking out pulls:\\n\"",
")",
"\n",
"\\n",
"\n",
"}",
"\n",
"for",
"_",
",",
"pull",
":=",
"range",
"record",
".",
"Refs",
".",
"Pulls",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"output",
",",
"\"#\\t%d\"",
",",
"\\t",
")",
"\n",
"pull",
".",
"Number",
"\n",
"if",
"pull",
".",
"SHA",
"!=",
"\"\"",
"{",
"fmt",
".",
"Fprintf",
"(",
"&",
"output",
",",
"\"(%s)\"",
",",
"pull",
".",
"SHA",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// FormatRecord describes the record in a human-readable
// manner for inclusion into build logs
|
[
"FormatRecord",
"describes",
"the",
"record",
"in",
"a",
"human",
"-",
"readable",
"manner",
"for",
"inclusion",
"into",
"build",
"logs"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pod-utils/clone/format.go#L26-L55
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
Namespace
|
func (c *Client) Namespace(ns string) *Client {
nc := *c
nc.namespace = ns
return &nc
}
|
go
|
func (c *Client) Namespace(ns string) *Client {
nc := *c
nc.namespace = ns
return &nc
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Namespace",
"(",
"ns",
"string",
")",
"*",
"Client",
"{",
"nc",
":=",
"*",
"c",
"\n",
"nc",
".",
"namespace",
"=",
"ns",
"\n",
"return",
"&",
"nc",
"\n",
"}"
] |
// Namespace returns a copy of the client pointing at the specified namespace.
|
[
"Namespace",
"returns",
"a",
"copy",
"of",
"the",
"client",
"pointing",
"at",
"the",
"specified",
"namespace",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L79-L83
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
NewFakeClient
|
func NewFakeClient(deckURL string) *Client {
return &Client{
namespace: "default",
deckURL: deckURL,
client: &http.Client{},
fake: true,
}
}
|
go
|
func NewFakeClient(deckURL string) *Client {
return &Client{
namespace: "default",
deckURL: deckURL,
client: &http.Client{},
fake: true,
}
}
|
[
"func",
"NewFakeClient",
"(",
"deckURL",
"string",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"namespace",
":",
"\"default\"",
",",
"deckURL",
":",
"deckURL",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"}",
",",
"fake",
":",
"true",
",",
"}",
"\n",
"}"
] |
// NewFakeClient creates a client that doesn't do anything. If you provide a
// deck URL then the client will hit that for the supported calls.
|
[
"NewFakeClient",
"creates",
"a",
"client",
"that",
"doesn",
"t",
"do",
"anything",
".",
"If",
"you",
"provide",
"a",
"deck",
"URL",
"then",
"the",
"client",
"will",
"hit",
"that",
"for",
"the",
"supported",
"calls",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L261-L268
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
NewClientInCluster
|
func NewClientInCluster(namespace string) (*Client, error) {
tokenFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"
token, err := ioutil.ReadFile(tokenFile)
if err != nil {
return nil, err
}
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
certData, err := ioutil.ReadFile(rootCAFile)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(certData)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
RootCAs: cp,
},
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: inClusterBaseURL,
client: &http.Client{Transport: tr, Timeout: requestTimeout},
token: string(token),
namespace: namespace,
}, nil
}
|
go
|
func NewClientInCluster(namespace string) (*Client, error) {
tokenFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"
token, err := ioutil.ReadFile(tokenFile)
if err != nil {
return nil, err
}
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
certData, err := ioutil.ReadFile(rootCAFile)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(certData)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
RootCAs: cp,
},
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: inClusterBaseURL,
client: &http.Client{Transport: tr, Timeout: requestTimeout},
token: string(token),
namespace: namespace,
}, nil
}
|
[
"func",
"NewClientInCluster",
"(",
"namespace",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"tokenFile",
":=",
"\"/var/run/secrets/kubernetes.io/serviceaccount/token\"",
"\n",
"token",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"tokenFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"rootCAFile",
":=",
"\"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt\"",
"\n",
"certData",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"rootCAFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cp",
":=",
"x509",
".",
"NewCertPool",
"(",
")",
"\n",
"cp",
".",
"AppendCertsFromPEM",
"(",
"certData",
")",
"\n",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"MinVersion",
":",
"tls",
".",
"VersionTLS12",
",",
"RootCAs",
":",
"cp",
",",
"}",
",",
"}",
"\n",
"return",
"&",
"Client",
"{",
"logger",
":",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"kube\"",
")",
",",
"baseURL",
":",
"inClusterBaseURL",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
",",
"Timeout",
":",
"requestTimeout",
"}",
",",
"token",
":",
"string",
"(",
"token",
")",
",",
"namespace",
":",
"namespace",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewClientInCluster creates a Client that works from within a pod.
|
[
"NewClientInCluster",
"creates",
"a",
"Client",
"that",
"works",
"from",
"within",
"a",
"pod",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L271-L300
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
NewClientFromFile
|
func NewClientFromFile(clusterPath, namespace string) (*Client, error) {
data, err := ioutil.ReadFile(clusterPath)
if err != nil {
return nil, err
}
var c Cluster
if err := yaml.Unmarshal(data, &c); err != nil {
return nil, err
}
return NewClient(&c, namespace)
}
|
go
|
func NewClientFromFile(clusterPath, namespace string) (*Client, error) {
data, err := ioutil.ReadFile(clusterPath)
if err != nil {
return nil, err
}
var c Cluster
if err := yaml.Unmarshal(data, &c); err != nil {
return nil, err
}
return NewClient(&c, namespace)
}
|
[
"func",
"NewClientFromFile",
"(",
"clusterPath",
",",
"namespace",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"clusterPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"c",
"Cluster",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewClient",
"(",
"&",
"c",
",",
"namespace",
")",
"\n",
"}"
] |
// NewClientFromFile reads a Cluster object at clusterPath and returns an
// authenticated client using the keys within.
|
[
"NewClientFromFile",
"reads",
"a",
"Cluster",
"object",
"at",
"clusterPath",
"and",
"returns",
"an",
"authenticated",
"client",
"using",
"the",
"keys",
"within",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L321-L331
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
NewClient
|
func NewClient(c *Cluster, namespace string) (*Client, error) {
// Relies on json encoding/decoding []byte as base64
// https://golang.org/pkg/encoding/json/#Marshal
cc := c.ClientCertificate
ck := c.ClientKey
ca := c.ClusterCACertificate
cert, err := tls.X509KeyPair(cc, ck)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(ca)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
RootCAs: cp,
},
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: c.Endpoint,
client: &http.Client{Transport: tr, Timeout: requestTimeout},
namespace: namespace,
}, nil
}
|
go
|
func NewClient(c *Cluster, namespace string) (*Client, error) {
// Relies on json encoding/decoding []byte as base64
// https://golang.org/pkg/encoding/json/#Marshal
cc := c.ClientCertificate
ck := c.ClientKey
ca := c.ClusterCACertificate
cert, err := tls.X509KeyPair(cc, ck)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(ca)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
RootCAs: cp,
},
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: c.Endpoint,
client: &http.Client{Transport: tr, Timeout: requestTimeout},
namespace: namespace,
}, nil
}
|
[
"func",
"NewClient",
"(",
"c",
"*",
"Cluster",
",",
"namespace",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"cc",
":=",
"c",
".",
"ClientCertificate",
"\n",
"ck",
":=",
"c",
".",
"ClientKey",
"\n",
"ca",
":=",
"c",
".",
"ClusterCACertificate",
"\n",
"cert",
",",
"err",
":=",
"tls",
".",
"X509KeyPair",
"(",
"cc",
",",
"ck",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cp",
":=",
"x509",
".",
"NewCertPool",
"(",
")",
"\n",
"cp",
".",
"AppendCertsFromPEM",
"(",
"ca",
")",
"\n",
"tr",
":=",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tls",
".",
"Config",
"{",
"MinVersion",
":",
"tls",
".",
"VersionTLS12",
",",
"Certificates",
":",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"cert",
"}",
",",
"RootCAs",
":",
"cp",
",",
"}",
",",
"}",
"\n",
"return",
"&",
"Client",
"{",
"logger",
":",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"kube\"",
")",
",",
"baseURL",
":",
"c",
".",
"Endpoint",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"tr",
",",
"Timeout",
":",
"requestTimeout",
"}",
",",
"namespace",
":",
"namespace",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewClient returns an authenticated Client using the keys in the Cluster.
|
[
"NewClient",
"returns",
"an",
"authenticated",
"Client",
"using",
"the",
"keys",
"in",
"the",
"Cluster",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L385-L413
|
test
|
kubernetes/test-infra
|
prow/kube/client.go
|
ReplaceConfigMap
|
func (c *Client) ReplaceConfigMap(name string, config ConfigMap) (ConfigMap, error) {
c.log("ReplaceConfigMap", name)
namespace := c.namespace
if config.Namespace != "" {
namespace = config.Namespace
}
var retConfigMap ConfigMap
err := c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", namespace, name),
requestBody: &config,
}, &retConfigMap)
return retConfigMap, err
}
|
go
|
func (c *Client) ReplaceConfigMap(name string, config ConfigMap) (ConfigMap, error) {
c.log("ReplaceConfigMap", name)
namespace := c.namespace
if config.Namespace != "" {
namespace = config.Namespace
}
var retConfigMap ConfigMap
err := c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", namespace, name),
requestBody: &config,
}, &retConfigMap)
return retConfigMap, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ReplaceConfigMap",
"(",
"name",
"string",
",",
"config",
"ConfigMap",
")",
"(",
"ConfigMap",
",",
"error",
")",
"{",
"c",
".",
"log",
"(",
"\"ReplaceConfigMap\"",
",",
"name",
")",
"\n",
"namespace",
":=",
"c",
".",
"namespace",
"\n",
"if",
"config",
".",
"Namespace",
"!=",
"\"\"",
"{",
"namespace",
"=",
"config",
".",
"Namespace",
"\n",
"}",
"\n",
"var",
"retConfigMap",
"ConfigMap",
"\n",
"err",
":=",
"c",
".",
"request",
"(",
"&",
"request",
"{",
"method",
":",
"http",
".",
"MethodPut",
",",
"path",
":",
"fmt",
".",
"Sprintf",
"(",
"\"/api/v1/namespaces/%s/configmaps/%s\"",
",",
"namespace",
",",
"name",
")",
",",
"requestBody",
":",
"&",
"config",
",",
"}",
",",
"&",
"retConfigMap",
")",
"\n",
"return",
"retConfigMap",
",",
"err",
"\n",
"}"
] |
// ReplaceConfigMap puts the configmap into name.
//
// Analogous to kubectl replace configmap
//
// If config.Namespace is empty, the client's specified namespace is used.
// Returns the content returned by the apiserver
|
[
"ReplaceConfigMap",
"puts",
"the",
"configmap",
"into",
"name",
".",
"Analogous",
"to",
"kubectl",
"replace",
"configmap",
"If",
"config",
".",
"Namespace",
"is",
"empty",
"the",
"client",
"s",
"specified",
"namespace",
"is",
"used",
".",
"Returns",
"the",
"content",
"returned",
"by",
"the",
"apiserver"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/client.go#L617-L631
|
test
|
kubernetes/test-infra
|
greenhouse/diskutil/diskutil.go
|
GetDiskUsage
|
func GetDiskUsage(path string) (percentBlocksFree float64, bytesFree, bytesUsed uint64, err error) {
var stat syscall.Statfs_t
err = syscall.Statfs(path, &stat)
if err != nil {
return 0, 0, 0, err
}
percentBlocksFree = float64(stat.Bfree) / float64(stat.Blocks) * 100
bytesFree = stat.Bfree * uint64(stat.Bsize)
bytesUsed = (stat.Blocks - stat.Bfree) * uint64(stat.Bsize)
return percentBlocksFree, bytesFree, bytesUsed, nil
}
|
go
|
func GetDiskUsage(path string) (percentBlocksFree float64, bytesFree, bytesUsed uint64, err error) {
var stat syscall.Statfs_t
err = syscall.Statfs(path, &stat)
if err != nil {
return 0, 0, 0, err
}
percentBlocksFree = float64(stat.Bfree) / float64(stat.Blocks) * 100
bytesFree = stat.Bfree * uint64(stat.Bsize)
bytesUsed = (stat.Blocks - stat.Bfree) * uint64(stat.Bsize)
return percentBlocksFree, bytesFree, bytesUsed, nil
}
|
[
"func",
"GetDiskUsage",
"(",
"path",
"string",
")",
"(",
"percentBlocksFree",
"float64",
",",
"bytesFree",
",",
"bytesUsed",
"uint64",
",",
"err",
"error",
")",
"{",
"var",
"stat",
"syscall",
".",
"Statfs_t",
"\n",
"err",
"=",
"syscall",
".",
"Statfs",
"(",
"path",
",",
"&",
"stat",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"0",
",",
"err",
"\n",
"}",
"\n",
"percentBlocksFree",
"=",
"float64",
"(",
"stat",
".",
"Bfree",
")",
"/",
"float64",
"(",
"stat",
".",
"Blocks",
")",
"*",
"100",
"\n",
"bytesFree",
"=",
"stat",
".",
"Bfree",
"*",
"uint64",
"(",
"stat",
".",
"Bsize",
")",
"\n",
"bytesUsed",
"=",
"(",
"stat",
".",
"Blocks",
"-",
"stat",
".",
"Bfree",
")",
"*",
"uint64",
"(",
"stat",
".",
"Bsize",
")",
"\n",
"return",
"percentBlocksFree",
",",
"bytesFree",
",",
"bytesUsed",
",",
"nil",
"\n",
"}"
] |
// GetDiskUsage wraps syscall.Statfs for usage in GCing the disk
|
[
"GetDiskUsage",
"wraps",
"syscall",
".",
"Statfs",
"for",
"usage",
"in",
"GCing",
"the",
"disk"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/greenhouse/diskutil/diskutil.go#L29-L39
|
test
|
kubernetes/test-infra
|
greenhouse/diskutil/diskutil.go
|
GetATime
|
func GetATime(path string, defaultTime time.Time) time.Time {
at, err := atime.Stat(path)
if err != nil {
log.WithError(err).Errorf("Could not get atime for %s", path)
return defaultTime
}
return at
}
|
go
|
func GetATime(path string, defaultTime time.Time) time.Time {
at, err := atime.Stat(path)
if err != nil {
log.WithError(err).Errorf("Could not get atime for %s", path)
return defaultTime
}
return at
}
|
[
"func",
"GetATime",
"(",
"path",
"string",
",",
"defaultTime",
"time",
".",
"Time",
")",
"time",
".",
"Time",
"{",
"at",
",",
"err",
":=",
"atime",
".",
"Stat",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"Could not get atime for %s\"",
",",
"path",
")",
"\n",
"return",
"defaultTime",
"\n",
"}",
"\n",
"return",
"at",
"\n",
"}"
] |
// GetATime the atime for a file, logging errors instead of failing
// and returning defaultTime instead
|
[
"GetATime",
"the",
"atime",
"for",
"a",
"file",
"logging",
"errors",
"instead",
"of",
"failing",
"and",
"returning",
"defaultTime",
"instead"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/greenhouse/diskutil/diskutil.go#L43-L50
|
test
|
kubernetes/test-infra
|
prow/spyglass/lenses/lenses.go
|
RegisterLens
|
func RegisterLens(lens Lens) error {
config := lens.Config()
_, ok := lensReg[config.Name]
if ok {
return fmt.Errorf("viewer already registered with name %s", config.Name)
}
if config.Title == "" {
return errors.New("empty title field in view metadata")
}
if config.Priority < 0 {
return errors.New("priority must be >=0")
}
lensReg[config.Name] = lens
logrus.Infof("Spyglass registered viewer %s with title %s.", config.Name, config.Title)
return nil
}
|
go
|
func RegisterLens(lens Lens) error {
config := lens.Config()
_, ok := lensReg[config.Name]
if ok {
return fmt.Errorf("viewer already registered with name %s", config.Name)
}
if config.Title == "" {
return errors.New("empty title field in view metadata")
}
if config.Priority < 0 {
return errors.New("priority must be >=0")
}
lensReg[config.Name] = lens
logrus.Infof("Spyglass registered viewer %s with title %s.", config.Name, config.Title)
return nil
}
|
[
"func",
"RegisterLens",
"(",
"lens",
"Lens",
")",
"error",
"{",
"config",
":=",
"lens",
".",
"Config",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"lensReg",
"[",
"config",
".",
"Name",
"]",
"\n",
"if",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"viewer already registered with name %s\"",
",",
"config",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Title",
"==",
"\"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"empty title field in view metadata\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Priority",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"priority must be >=0\"",
")",
"\n",
"}",
"\n",
"lensReg",
"[",
"config",
".",
"Name",
"]",
"=",
"lens",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Spyglass registered viewer %s with title %s.\"",
",",
"config",
".",
"Name",
",",
"config",
".",
"Title",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// RegisterLens registers new viewers
|
[
"RegisterLens",
"registers",
"new",
"viewers"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/lenses/lenses.go#L96-L112
|
test
|
kubernetes/test-infra
|
prow/spyglass/lenses/lenses.go
|
GetLens
|
func GetLens(name string) (Lens, error) {
lens, ok := lensReg[name]
if !ok {
return nil, ErrInvalidLensName
}
return lens, nil
}
|
go
|
func GetLens(name string) (Lens, error) {
lens, ok := lensReg[name]
if !ok {
return nil, ErrInvalidLensName
}
return lens, nil
}
|
[
"func",
"GetLens",
"(",
"name",
"string",
")",
"(",
"Lens",
",",
"error",
")",
"{",
"lens",
",",
"ok",
":=",
"lensReg",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrInvalidLensName",
"\n",
"}",
"\n",
"return",
"lens",
",",
"nil",
"\n",
"}"
] |
// GetLens returns a Lens by name, if it exists; otherwise it returns an error.
|
[
"GetLens",
"returns",
"a",
"Lens",
"by",
"name",
"if",
"it",
"exists",
";",
"otherwise",
"it",
"returns",
"an",
"error",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/lenses/lenses.go#L115-L121
|
test
|
kubernetes/test-infra
|
prow/spyglass/lenses/lenses.go
|
LastNLines
|
func LastNLines(a Artifact, n int64) ([]string, error) {
// 300B, a reasonable log line length, probably a bit more scalable than a hard-coded value
return LastNLinesChunked(a, n, 300*n+1)
}
|
go
|
func LastNLines(a Artifact, n int64) ([]string, error) {
// 300B, a reasonable log line length, probably a bit more scalable than a hard-coded value
return LastNLinesChunked(a, n, 300*n+1)
}
|
[
"func",
"LastNLines",
"(",
"a",
"Artifact",
",",
"n",
"int64",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"LastNLinesChunked",
"(",
"a",
",",
"n",
",",
"300",
"*",
"n",
"+",
"1",
")",
"\n",
"}"
] |
// LastNLines reads the last n lines from an artifact.
|
[
"LastNLines",
"reads",
"the",
"last",
"n",
"lines",
"from",
"an",
"artifact",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/lenses/lenses.go#L130-L133
|
test
|
kubernetes/test-infra
|
prow/slack/client.go
|
NewClient
|
func NewClient(tokenGenerator func() []byte) *Client {
return &Client{
logger: logrus.WithField("client", "slack"),
tokenGenerator: tokenGenerator,
}
}
|
go
|
func NewClient(tokenGenerator func() []byte) *Client {
return &Client{
logger: logrus.WithField("client", "slack"),
tokenGenerator: tokenGenerator,
}
}
|
[
"func",
"NewClient",
"(",
"tokenGenerator",
"func",
"(",
")",
"[",
"]",
"byte",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"logger",
":",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"slack\"",
")",
",",
"tokenGenerator",
":",
"tokenGenerator",
",",
"}",
"\n",
"}"
] |
// NewClient creates a slack client with an API token.
|
[
"NewClient",
"creates",
"a",
"slack",
"client",
"with",
"an",
"API",
"token",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/slack/client.go#L53-L58
|
test
|
kubernetes/test-infra
|
prow/slack/client.go
|
WriteMessage
|
func (sl *Client) WriteMessage(text, channel string) error {
sl.log("WriteMessage", text, channel)
if sl.fake {
return nil
}
var uv = sl.urlValues()
uv.Add("channel", channel)
uv.Add("text", text)
_, err := sl.postMessage(chatPostMessage, uv)
return err
}
|
go
|
func (sl *Client) WriteMessage(text, channel string) error {
sl.log("WriteMessage", text, channel)
if sl.fake {
return nil
}
var uv = sl.urlValues()
uv.Add("channel", channel)
uv.Add("text", text)
_, err := sl.postMessage(chatPostMessage, uv)
return err
}
|
[
"func",
"(",
"sl",
"*",
"Client",
")",
"WriteMessage",
"(",
"text",
",",
"channel",
"string",
")",
"error",
"{",
"sl",
".",
"log",
"(",
"\"WriteMessage\"",
",",
"text",
",",
"channel",
")",
"\n",
"if",
"sl",
".",
"fake",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"uv",
"=",
"sl",
".",
"urlValues",
"(",
")",
"\n",
"uv",
".",
"Add",
"(",
"\"channel\"",
",",
"channel",
")",
"\n",
"uv",
".",
"Add",
"(",
"\"text\"",
",",
"text",
")",
"\n",
"_",
",",
"err",
":=",
"sl",
".",
"postMessage",
"(",
"chatPostMessage",
",",
"uv",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// WriteMessage adds text to channel
|
[
"WriteMessage",
"adds",
"text",
"to",
"channel"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/slack/client.go#L102-L114
|
test
|
kubernetes/test-infra
|
maintenance/aws-janitor/resources/nat_gateway.go
|
MarkAndSweep
|
func (NATGateway) MarkAndSweep(sess *session.Session, acct string, region string, set *Set) error {
svc := ec2.New(sess, &aws.Config{Region: aws.String(region)})
inp := &ec2.DescribeNatGatewaysInput{}
if err := svc.DescribeNatGatewaysPages(inp, func(page *ec2.DescribeNatGatewaysOutput, _ bool) bool {
for _, gw := range page.NatGateways {
g := &natGateway{
Account: acct,
Region: region,
ID: *gw.NatGatewayId,
}
if set.Mark(g) {
inp := &ec2.DeleteNatGatewayInput{NatGatewayId: gw.NatGatewayId}
if _, err := svc.DeleteNatGateway(inp); err != nil {
klog.Warningf("%v: delete failed: %v", g.ARN(), err)
}
}
}
return true
}); err != nil {
return err
}
return nil
}
|
go
|
func (NATGateway) MarkAndSweep(sess *session.Session, acct string, region string, set *Set) error {
svc := ec2.New(sess, &aws.Config{Region: aws.String(region)})
inp := &ec2.DescribeNatGatewaysInput{}
if err := svc.DescribeNatGatewaysPages(inp, func(page *ec2.DescribeNatGatewaysOutput, _ bool) bool {
for _, gw := range page.NatGateways {
g := &natGateway{
Account: acct,
Region: region,
ID: *gw.NatGatewayId,
}
if set.Mark(g) {
inp := &ec2.DeleteNatGatewayInput{NatGatewayId: gw.NatGatewayId}
if _, err := svc.DeleteNatGateway(inp); err != nil {
klog.Warningf("%v: delete failed: %v", g.ARN(), err)
}
}
}
return true
}); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"NATGateway",
")",
"MarkAndSweep",
"(",
"sess",
"*",
"session",
".",
"Session",
",",
"acct",
"string",
",",
"region",
"string",
",",
"set",
"*",
"Set",
")",
"error",
"{",
"svc",
":=",
"ec2",
".",
"New",
"(",
"sess",
",",
"&",
"aws",
".",
"Config",
"{",
"Region",
":",
"aws",
".",
"String",
"(",
"region",
")",
"}",
")",
"\n",
"inp",
":=",
"&",
"ec2",
".",
"DescribeNatGatewaysInput",
"{",
"}",
"\n",
"if",
"err",
":=",
"svc",
".",
"DescribeNatGatewaysPages",
"(",
"inp",
",",
"func",
"(",
"page",
"*",
"ec2",
".",
"DescribeNatGatewaysOutput",
",",
"_",
"bool",
")",
"bool",
"{",
"for",
"_",
",",
"gw",
":=",
"range",
"page",
".",
"NatGateways",
"{",
"g",
":=",
"&",
"natGateway",
"{",
"Account",
":",
"acct",
",",
"Region",
":",
"region",
",",
"ID",
":",
"*",
"gw",
".",
"NatGatewayId",
",",
"}",
"\n",
"if",
"set",
".",
"Mark",
"(",
"g",
")",
"{",
"inp",
":=",
"&",
"ec2",
".",
"DeleteNatGatewayInput",
"{",
"NatGatewayId",
":",
"gw",
".",
"NatGatewayId",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"svc",
".",
"DeleteNatGateway",
"(",
"inp",
")",
";",
"err",
"!=",
"nil",
"{",
"klog",
".",
"Warningf",
"(",
"\"%v: delete failed: %v\"",
",",
"g",
".",
"ARN",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// MarkAndSweep looks at the provided set, and removes resources older than its TTL that have been previously tagged.
|
[
"MarkAndSweep",
"looks",
"at",
"the",
"provided",
"set",
"and",
"removes",
"resources",
"older",
"than",
"its",
"TTL",
"that",
"have",
"been",
"previously",
"tagged",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/maintenance/aws-janitor/resources/nat_gateway.go#L36-L61
|
test
|
kubernetes/test-infra
|
maintenance/aws-janitor/resources/nat_gateway.go
|
ListAll
|
func (NATGateway) ListAll(sess *session.Session, acct, region string) (*Set, error) {
svc := ec2.New(sess, &aws.Config{Region: aws.String(region)})
set := NewSet(0)
inp := &ec2.DescribeNatGatewaysInput{}
err := svc.DescribeNatGatewaysPages(inp, func(page *ec2.DescribeNatGatewaysOutput, _ bool) bool {
for _, gw := range page.NatGateways {
now := time.Now()
arn := natGateway{
Account: acct,
Region: region,
ID: *gw.NatGatewayId,
}.ARN()
set.firstSeen[arn] = now
}
return true
})
return set, errors.Wrapf(err, "couldn't describe nat gateways for %q in %q", acct, region)
}
|
go
|
func (NATGateway) ListAll(sess *session.Session, acct, region string) (*Set, error) {
svc := ec2.New(sess, &aws.Config{Region: aws.String(region)})
set := NewSet(0)
inp := &ec2.DescribeNatGatewaysInput{}
err := svc.DescribeNatGatewaysPages(inp, func(page *ec2.DescribeNatGatewaysOutput, _ bool) bool {
for _, gw := range page.NatGateways {
now := time.Now()
arn := natGateway{
Account: acct,
Region: region,
ID: *gw.NatGatewayId,
}.ARN()
set.firstSeen[arn] = now
}
return true
})
return set, errors.Wrapf(err, "couldn't describe nat gateways for %q in %q", acct, region)
}
|
[
"func",
"(",
"NATGateway",
")",
"ListAll",
"(",
"sess",
"*",
"session",
".",
"Session",
",",
"acct",
",",
"region",
"string",
")",
"(",
"*",
"Set",
",",
"error",
")",
"{",
"svc",
":=",
"ec2",
".",
"New",
"(",
"sess",
",",
"&",
"aws",
".",
"Config",
"{",
"Region",
":",
"aws",
".",
"String",
"(",
"region",
")",
"}",
")",
"\n",
"set",
":=",
"NewSet",
"(",
"0",
")",
"\n",
"inp",
":=",
"&",
"ec2",
".",
"DescribeNatGatewaysInput",
"{",
"}",
"\n",
"err",
":=",
"svc",
".",
"DescribeNatGatewaysPages",
"(",
"inp",
",",
"func",
"(",
"page",
"*",
"ec2",
".",
"DescribeNatGatewaysOutput",
",",
"_",
"bool",
")",
"bool",
"{",
"for",
"_",
",",
"gw",
":=",
"range",
"page",
".",
"NatGateways",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"arn",
":=",
"natGateway",
"{",
"Account",
":",
"acct",
",",
"Region",
":",
"region",
",",
"ID",
":",
"*",
"gw",
".",
"NatGatewayId",
",",
"}",
".",
"ARN",
"(",
")",
"\n",
"set",
".",
"firstSeen",
"[",
"arn",
"]",
"=",
"now",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"return",
"set",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"couldn't describe nat gateways for %q in %q\"",
",",
"acct",
",",
"region",
")",
"\n",
"}"
] |
// ListAll populates a set will all available NATGateway resources.
|
[
"ListAll",
"populates",
"a",
"set",
"will",
"all",
"available",
"NATGateway",
"resources",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/maintenance/aws-janitor/resources/nat_gateway.go#L64-L85
|
test
|
kubernetes/test-infra
|
boskos/client/client.go
|
NewClient
|
func NewClient(owner string, url string) *Client {
client := &Client{
url: url,
owner: owner,
storage: storage.NewMemoryStorage(),
}
// Configure the dialer to attempt three additional times to establish
// a connection after a failed dial attempt. The dialer should wait 10
// seconds between each attempt.
client.Dialer.RetryCount = 3
client.Dialer.RetrySleep = time.Second * 10
// Configure the dialer and HTTP client transport to mimic the configuration
// of the http.DefaultTransport with the exception that the Dialer's Dial
// and DialContext functions are assigned to the client transport.
//
// See https://golang.org/pkg/net/http/#RoundTripper for the values
// values used for the http.DefaultTransport.
client.Dialer.Timeout = 30 * time.Second
client.Dialer.KeepAlive = 30 * time.Second
client.Dialer.DualStack = true
client.http.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: client.Dialer.Dial,
DialContext: client.Dialer.DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return client
}
|
go
|
func NewClient(owner string, url string) *Client {
client := &Client{
url: url,
owner: owner,
storage: storage.NewMemoryStorage(),
}
// Configure the dialer to attempt three additional times to establish
// a connection after a failed dial attempt. The dialer should wait 10
// seconds between each attempt.
client.Dialer.RetryCount = 3
client.Dialer.RetrySleep = time.Second * 10
// Configure the dialer and HTTP client transport to mimic the configuration
// of the http.DefaultTransport with the exception that the Dialer's Dial
// and DialContext functions are assigned to the client transport.
//
// See https://golang.org/pkg/net/http/#RoundTripper for the values
// values used for the http.DefaultTransport.
client.Dialer.Timeout = 30 * time.Second
client.Dialer.KeepAlive = 30 * time.Second
client.Dialer.DualStack = true
client.http.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: client.Dialer.Dial,
DialContext: client.Dialer.DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return client
}
|
[
"func",
"NewClient",
"(",
"owner",
"string",
",",
"url",
"string",
")",
"*",
"Client",
"{",
"client",
":=",
"&",
"Client",
"{",
"url",
":",
"url",
",",
"owner",
":",
"owner",
",",
"storage",
":",
"storage",
".",
"NewMemoryStorage",
"(",
")",
",",
"}",
"\n",
"client",
".",
"Dialer",
".",
"RetryCount",
"=",
"3",
"\n",
"client",
".",
"Dialer",
".",
"RetrySleep",
"=",
"time",
".",
"Second",
"*",
"10",
"\n",
"client",
".",
"Dialer",
".",
"Timeout",
"=",
"30",
"*",
"time",
".",
"Second",
"\n",
"client",
".",
"Dialer",
".",
"KeepAlive",
"=",
"30",
"*",
"time",
".",
"Second",
"\n",
"client",
".",
"Dialer",
".",
"DualStack",
"=",
"true",
"\n",
"client",
".",
"http",
".",
"Transport",
"=",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"Dial",
":",
"client",
".",
"Dialer",
".",
"Dial",
",",
"DialContext",
":",
"client",
".",
"Dialer",
".",
"DialContext",
",",
"MaxIdleConns",
":",
"100",
",",
"IdleConnTimeout",
":",
"90",
"*",
"time",
".",
"Second",
",",
"TLSHandshakeTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"ExpectContinueTimeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"}",
"\n",
"return",
"client",
"\n",
"}"
] |
// NewClient creates a Boskos client for the specified URL and resource owner.
//
// Clients created with this function default to retrying failed connection
// attempts three times with a ten second pause between each attempt.
|
[
"NewClient",
"creates",
"a",
"Boskos",
"client",
"for",
"the",
"specified",
"URL",
"and",
"resource",
"owner",
".",
"Clients",
"created",
"with",
"this",
"function",
"default",
"to",
"retrying",
"failed",
"connection",
"attempts",
"three",
"times",
"with",
"a",
"ten",
"second",
"pause",
"between",
"each",
"attempt",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/client/client.go#L72-L106
|
test
|
kubernetes/test-infra
|
boskos/client/client.go
|
Acquire
|
func (c *Client) Acquire(rtype, state, dest string) (*common.Resource, error) {
r, err := c.acquire(rtype, state, dest)
if err != nil {
return nil, err
}
c.lock.Lock()
defer c.lock.Unlock()
if r != nil {
c.storage.Add(*r)
}
return r, nil
}
|
go
|
func (c *Client) Acquire(rtype, state, dest string) (*common.Resource, error) {
r, err := c.acquire(rtype, state, dest)
if err != nil {
return nil, err
}
c.lock.Lock()
defer c.lock.Unlock()
if r != nil {
c.storage.Add(*r)
}
return r, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Acquire",
"(",
"rtype",
",",
"state",
",",
"dest",
"string",
")",
"(",
"*",
"common",
".",
"Resource",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"c",
".",
"acquire",
"(",
"rtype",
",",
"state",
",",
"dest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"r",
"!=",
"nil",
"{",
"c",
".",
"storage",
".",
"Add",
"(",
"*",
"r",
")",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] |
// public method
// Acquire asks boskos for a resource of certain type in certain state, and set the resource to dest state.
// Returns the resource on success.
|
[
"public",
"method",
"Acquire",
"asks",
"boskos",
"for",
"a",
"resource",
"of",
"certain",
"type",
"in",
"certain",
"state",
"and",
"set",
"the",
"resource",
"to",
"dest",
"state",
".",
"Returns",
"the",
"resource",
"on",
"success",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/client/client.go#L112-L124
|
test
|
kubernetes/test-infra
|
boskos/client/client.go
|
AcquireWait
|
func (c *Client) AcquireWait(ctx context.Context, rtype, state, dest string) (*common.Resource, error) {
if ctx == nil {
return nil, ErrContextRequired
}
// Try to acquire the resource until available or the context is
// cancelled or its deadline exceeded.
for {
r, err := c.Acquire(rtype, state, dest)
if err != nil {
if err == ErrAlreadyInUse || err == ErrNotFound {
select {
case <-ctx.Done():
return nil, err
case <-time.After(3 * time.Second):
continue
}
}
return nil, err
}
return r, nil
}
}
|
go
|
func (c *Client) AcquireWait(ctx context.Context, rtype, state, dest string) (*common.Resource, error) {
if ctx == nil {
return nil, ErrContextRequired
}
// Try to acquire the resource until available or the context is
// cancelled or its deadline exceeded.
for {
r, err := c.Acquire(rtype, state, dest)
if err != nil {
if err == ErrAlreadyInUse || err == ErrNotFound {
select {
case <-ctx.Done():
return nil, err
case <-time.After(3 * time.Second):
continue
}
}
return nil, err
}
return r, nil
}
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AcquireWait",
"(",
"ctx",
"context",
".",
"Context",
",",
"rtype",
",",
"state",
",",
"dest",
"string",
")",
"(",
"*",
"common",
".",
"Resource",
",",
"error",
")",
"{",
"if",
"ctx",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrContextRequired",
"\n",
"}",
"\n",
"for",
"{",
"r",
",",
"err",
":=",
"c",
".",
"Acquire",
"(",
"rtype",
",",
"state",
",",
"dest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"ErrAlreadyInUse",
"||",
"err",
"==",
"ErrNotFound",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"nil",
",",
"err",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"3",
"*",
"time",
".",
"Second",
")",
":",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// AcquireWait blocks until Acquire returns the specified resource or the
// provided context is cancelled or its deadline exceeded.
|
[
"AcquireWait",
"blocks",
"until",
"Acquire",
"returns",
"the",
"specified",
"resource",
"or",
"the",
"provided",
"context",
"is",
"cancelled",
"or",
"its",
"deadline",
"exceeded",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/client/client.go#L128-L149
|
test
|
kubernetes/test-infra
|
boskos/client/client.go
|
AcquireByState
|
func (c *Client) AcquireByState(state, dest string, names []string) ([]common.Resource, error) {
resources, err := c.acquireByState(state, dest, names)
if err != nil {
return nil, err
}
c.lock.Lock()
defer c.lock.Unlock()
for _, r := range resources {
c.storage.Add(r)
}
return resources, nil
}
|
go
|
func (c *Client) AcquireByState(state, dest string, names []string) ([]common.Resource, error) {
resources, err := c.acquireByState(state, dest, names)
if err != nil {
return nil, err
}
c.lock.Lock()
defer c.lock.Unlock()
for _, r := range resources {
c.storage.Add(r)
}
return resources, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AcquireByState",
"(",
"state",
",",
"dest",
"string",
",",
"names",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"common",
".",
"Resource",
",",
"error",
")",
"{",
"resources",
",",
"err",
":=",
"c",
".",
"acquireByState",
"(",
"state",
",",
"dest",
",",
"names",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"resources",
"{",
"c",
".",
"storage",
".",
"Add",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"resources",
",",
"nil",
"\n",
"}"
] |
// AcquireByState asks boskos for a resources of certain type, and set the resource to dest state.
// Returns a list of resources on success.
|
[
"AcquireByState",
"asks",
"boskos",
"for",
"a",
"resources",
"of",
"certain",
"type",
"and",
"set",
"the",
"resource",
"to",
"dest",
"state",
".",
"Returns",
"a",
"list",
"of",
"resources",
"on",
"success",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/client/client.go#L153-L164
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.