Remove legacy JobResponse stuct fields - step 1

parent 11eacada
......@@ -60,7 +60,7 @@ func (b *buildsHelper) addBuild(build *common.Build) {
}
runners[otherBuild.RunnerID] = true
if otherBuild.ProjectID != build.ProjectID {
if otherBuild.JobInfo.ProjectID != build.JobInfo.ProjectID {
continue
}
projectRunners[otherBuild.ProjectRunnerID] = true
......
......@@ -224,18 +224,23 @@ func (c *ExecCommand) createBuild(repoURL string, abortSignal chan os.Signal) (b
build = &common.Build{
JobResponse: common.JobResponse{
ID: 1,
ProjectID: 1,
RepoURL: repoURL,
Commands: "",
Sha: strings.TrimSpace(sha),
RefName: strings.TrimSpace(refName),
BeforeSha: strings.TrimSpace(beforeSha),
AllowGitFetch: false,
Timeout: c.getTimeout(),
Token: "",
Name: "",
Stage: "",
Tag: false,
AllowGitFetch: false,
JobInfo: common.JRJobInfo{
Name: "",
Stage: "",
ProjectID: 1,
ProjectName: "",
},
GitInfo: common.JRGitInfo{
RepoURL: repoURL,
Ref: strings.TrimSpace(refName),
Sha: strings.TrimSpace(sha),
BeforeSha: strings.TrimSpace(beforeSha),
},
RunnerInfo: common.JRRunnerInfo{
Timeout: c.getTimeout(),
},
},
Runner: &common.RunnerConfig{
RunnerSettings: c.RunnerSettings,
......
......@@ -78,12 +78,12 @@ type Build struct {
}
func (b *Build) Log() *logrus.Entry {
return b.Runner.Log().WithField("build", b.ID).WithField("project", b.ProjectID)
return b.Runner.Log().WithField("job", b.ID).WithField("project", b.JobInfo.ProjectID)
}
func (b *Build) ProjectUniqueName() string {
return fmt.Sprintf("runner-%s-project-%d-concurrent-%d",
b.Runner.ShortDescription(), b.ProjectID, b.ProjectRunnerID)
b.Runner.ShortDescription(), b.JobInfo.ProjectID, b.ProjectRunnerID)
}
func (b *Build) ProjectSlug() (string, error) {
......@@ -110,7 +110,7 @@ func (b *Build) ProjectSlug() (string, error) {
func (b *Build) ProjectUniqueDir(sharedDir bool) string {
dir, err := b.ProjectSlug()
if err != nil {
dir = fmt.Sprintf("project-%d", b.ProjectID)
dir = fmt.Sprintf("project-%d", b.JobInfo.ProjectID)
}
// for shared dirs path is constructed like this:
......@@ -368,7 +368,7 @@ func (b *Build) GetDefaultVariables() BuildVariables {
{"CI_BUILD_ID", strconv.Itoa(b.ID), true, true, false},
{"CI_BUILD_REPO", b.RepoURL, true, true, false},
{"CI_BUILD_TOKEN", b.Token, true, true, false},
{"CI_PROJECT_ID", strconv.Itoa(b.ProjectID), true, true, false},
{"CI_PROJECT_ID", strconv.Itoa(b.JobInfo.ProjectID), true, true, false},
{"CI_PROJECT_DIR", b.FullProjectDir(), true, true, false},
{"CI_SERVER", "yes", true, true, false},
{"CI_SERVER_NAME", "GitLab CI", true, true, false},
......
......@@ -199,8 +199,8 @@ type JRDependencyArtifactsFile struct {
}
type JRDependency struct {
ID int `json:"id"`
Name string `json:"name"`
ID int `json:"id"`
Name string `json:"name"`
ArtifactsFile JRDependencyArtifactsFile `json:"artifacts_file"`
}
......@@ -223,7 +223,6 @@ type JobResponse struct {
Dependencies JRDependencies `json:"dependencies"`
// TODO: LEGACY KEYS - TO BE REFACTORIZED WITH USAGE!!!
ProjectID int `json:"project_id,omitempty"`
Commands string `json:"commands,omitempty"`
RepoURL string `json:"repo_url,omitempty"`
Sha string `json:"sha,omitempty"`
......@@ -239,8 +238,8 @@ type JobResponse struct {
TLSCAChain string `json:"-"`
}
func (b *JobResponse) RepoCleanURL() string {
return url_helpers.CleanURL(b.GitInfo.RepoURL)
func (j *JobResponse) RepoCleanURL() string {
return url_helpers.CleanURL(j.GitInfo.RepoURL)
}
// ---[ JobResponse END ]---
......
......@@ -265,7 +265,7 @@ func (s *executor) getLabels(containerType string, otherLabels ...string) map[st
labels[dockerLabelPrefix+".build.sha"] = s.Build.Sha
labels[dockerLabelPrefix+".build.before_sha"] = s.Build.BeforeSha
labels[dockerLabelPrefix+".build.ref_name"] = s.Build.RefName
labels[dockerLabelPrefix+".project.id"] = strconv.Itoa(s.Build.ProjectID)
labels[dockerLabelPrefix+".project.id"] = strconv.Itoa(s.Build.JobInfo.ProjectID)
labels[dockerLabelPrefix+".runner.id"] = s.Build.Runner.ShortDescription()
labels[dockerLabelPrefix+".runner.local_id"] = strconv.Itoa(s.Build.RunnerID)
labels[dockerLabelPrefix+".type"] = containerType
......
......@@ -138,7 +138,7 @@ func testServiceFromNamedImage(t *testing.T, description, imageName, serviceName
ProjectRunnerID: 0,
Runner: &common.RunnerConfig{},
}
e.Build.ProjectID = 0
e.Build.JobInfo.ProjectID = 0
e.Build.Runner.Token = "abcdef1234567890"
c.On("ImagePullBlocking", context.TODO(), imageName, options).
......
......@@ -174,6 +174,8 @@ func (n *GitLabClient) RequestJob(config common.RunnerConfig) (*common.JobRespon
var response common.JobResponse
result, statusText, certificates := n.doJSON(&config.RunnerCredentials, "POST", "jobs/request", 201, &request, &response)
fmt.Printf("\n%v\n", response)
switch result {
case 201:
config.Log().WithFields(logrus.Fields{
......
......@@ -42,7 +42,7 @@ func getCacheObjectName(build *common.Build, cache *common.CacheConfig, key stri
if !cache.Shared {
runnerSegment = path.Join("runner", build.Runner.ShortDescription())
}
return path.Join(cache.Path, runnerSegment, "project", strconv.Itoa(build.ProjectID), key)
return path.Join(cache.Path, runnerSegment, "project", strconv.Itoa(build.JobInfo.ProjectID), key)
}
func getCacheStorageClient(cache *common.CacheConfig) (scl *minio.Client, err error) {
......@@ -69,7 +69,7 @@ func getS3DownloadURL(build *common.Build, key string) (url *url.URL) {
return
}
url, err = scl.PresignedGetObject(cache.BucketName, objectName, time.Second*time.Duration(build.Timeout), nil)
url, err = scl.PresignedGetObject(cache.BucketName, objectName, time.Second*time.Duration(build.RunnerInfo.Timeout), nil)
if err != nil {
logrus.Warningln(err)
return
......@@ -103,7 +103,7 @@ func getS3UploadURL(build *common.Build, key string) (url *url.URL) {
return
}
url, err = scl.PresignedPutObject(cache.BucketName, objectName, time.Second*time.Duration(build.Timeout))
url, err = scl.PresignedPutObject(cache.BucketName, objectName, time.Second*time.Duration(build.RunnerInfo.Timeout))
if err != nil {
logrus.Warningln(err)
return
......
......@@ -22,8 +22,12 @@ func defaultS3CacheFactory() *common.CacheConfig {
var s3CacheBuild = &common.Build{
JobResponse: common.JobResponse{
ProjectID: 10,
Timeout: 3600,
JobInfo: common.JRJobInfo{
ProjectID: 10,
},
RunnerInfo: common.JRRunnerInfo{
Timeout: 3600,
},
},
Runner: &common.RunnerConfig{
RunnerCredentials: common.RunnerCredentials{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment