-
Notifications
You must be signed in to change notification settings - Fork 2
/
project-info.go
82 lines (73 loc) · 2.57 KB
/
project-info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"net/url"
"github.com/forj-oss/forjj-modules/trace"
"github.com/forj-oss/goforjj"
)
type ProjectInfo struct {
ForjCommonStruct
dslRepo string
dslPath string
isDslDefault bool
IsProDeployment bool `yaml:"production-deployment,omitempty"`
}
func (pi *ProjectInfo) set_project_info(forj ForjCommonStruct) {
pi.ForjCommonStruct = forj
}
func (pi *ProjectInfo) setDslInfo(seedJob SeedJobStruct) {
if seedJob.Path == "" && seedJob.Repo == "" {
pi.isDslDefault = true
pi.dslRepo = seedJob.DefaultRepo
pi.dslPath = seedJob.DefaultPath
} else {
pi.dslRepo = seedJob.Repo
pi.dslPath = seedJob.Path
}
}
func (pi *ProjectInfo) setIsProDeploy(isProDeployment bool) {
pi.IsProDeployment = isProDeployment
}
func (pi *ProjectInfo) set_projects_to(projects map[string]ProjectsInstanceStruct, r *JenkinsPlugin,
ret *goforjj.PluginData, status *bool, InfraName, defaultJenkinsfilePath string) (_ error) {
if pi.ForjjInfraUpstream == "" {
ret.StatusAdd("Unable to add a new project without a remote GIT repository. Jenkins JobDSL requirement. " +
"To enable this feature, add a remote GIT to your infra --infra-upstream or define the JobDSL Repository to clone.")
IsUpdated(status)
return
}
if v, err := url.Parse(pi.dslRepo); err != nil {
ret.Errorf("JobDSL: Infra remote URL issue. Check `seed-job-repo` parameter given by Forjj. %s", err)
return err
} else {
if v.Scheme == "" {
err = fmt.Errorf("JobDSL: Invalid Remote repository Url '%s'. Check `seed-job-repo` parameter given by Forjj. A scheme must exist", pi.dslRepo)
ret.Errorf("%s", err)
return err
}
}
// Initialize JobDSL structure
r.yaml.Projects = NewProjects(pi.ForjjInstanceName, pi.dslRepo, pi.dslPath, pi.isDslDefault)
// Retrieve list of Repository (projects) to manage
for name, prj := range projects {
jenkinsfilePath := ""
if prj.RepoDeployHosted != "true" {
gotrace.Trace("Project %s ignored, because not deploying in production an '%s' repo role.", name, prj.RepoRole)
continue
}
if prj.RepoRole == "code" { // Do not change Jenkinsfile Path setup for internal Forjj repository.
jenkinsfilePath = defaultJenkinsfilePath
}
if prj.JenkinsfilePath != "" { // But permit to change all repository one by one if needed, even on Forjj repository.
jenkinsfilePath = prj.JenkinsfilePath
}
switch prj.RemoteType {
case "github":
r.yaml.Projects.AddGithub(name, &prj.GithubStruct, prj.RepoRole, jenkinsfilePath)
case "git":
r.yaml.Projects.AddGit(name, &prj.GitStruct, prj.RepoRole, jenkinsfilePath)
}
}
IsUpdated(status)
return
}