Skip to content

Commit

Permalink
Refactor: export private structs
Browse files Browse the repository at this point in the history
  • Loading branch information
bndr committed Feb 5, 2017
1 parent 234c40c commit 71a45a7
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 84 deletions.
26 changes: 13 additions & 13 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

type Build struct {
Raw *buildResponse
Raw *BuildResponse
Job *Job
Jenkins *Jenkins
Base string
Expand All @@ -41,16 +41,16 @@ type branch struct {
Name string
}

type buildRevision struct {
type BuildRevision struct {
SHA1 string `json:"SHA1"`
Branch []branch `json:"branch"`
}

type builds struct {
type Builds struct {
BuildNumber int64 `json:"buildNumber"`
BuildResult interface{} `json:"buildResult"`
Marked buildRevision `json:"marked"`
Revision buildRevision `json:"revision"`
Marked BuildRevision `json:"marked"`
Revision BuildRevision `json:"revision"`
}

type culprit struct {
Expand All @@ -61,8 +61,8 @@ type culprit struct {
type generalObj struct {
Parameters []parameter `json:"parameters"`
Causes []map[string]interface{} `json:"causes"`
BuildsByBranchName map[string]builds `json:"buildsByBranchName"`
LastBuiltRevision buildRevision `json:"lastBuiltRevision"`
BuildsByBranchName map[string]Builds `json:"buildsByBranchName"`
LastBuiltRevision BuildRevision `json:"lastBuiltRevision"`
RemoteUrls []string `json:"remoteUrls"`
ScmName string `json:"scmName"`
MercurialNodeName string `json:"mercurialNodeName"`
Expand All @@ -72,7 +72,7 @@ type generalObj struct {
UrlName string
}

type testResult struct {
type TestResult struct {
Duration int64 `json:"duration"`
Empty bool `json:"empty"`
FailCount int64 `json:"failCount"`
Expand Down Expand Up @@ -102,7 +102,7 @@ type testResult struct {
} `json:"suites"`
}

type buildResponse struct {
type BuildResponse struct {
Actions []generalObj
Artifacts []struct {
DisplayPath string `json:"displayPath"`
Expand Down Expand Up @@ -157,7 +157,7 @@ type buildResponse struct {
}

// Builds
func (b *Build) Info() *buildResponse {
func (b *Build) Info() *BuildResponse {
return b.Raw
}

Expand Down Expand Up @@ -352,16 +352,16 @@ func (b *Build) GetMatrixRuns() ([]*Build, error) {
r, _ := regexp.Compile("job/(.*?)/(.*?)/(\\d+)/")

for i, run := range runs {
result[i] = &Build{Jenkins: b.Jenkins, Job: b.Job, Raw: new(buildResponse), Depth: 1, Base: "/" + r.FindString(run.Url)}
result[i] = &Build{Jenkins: b.Jenkins, Job: b.Job, Raw: new(BuildResponse), Depth: 1, Base: "/" + r.FindString(run.Url)}
result[i].Poll()
}
return result, nil
}

func (b *Build) GetResultSet() (*testResult, error) {
func (b *Build) GetResultSet() (*TestResult, error) {

url := b.Base + "/testReport"
var report testResult
var report TestResult

_, err := b.Jenkins.Requester.GetJSON(url, &report, nil)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions build_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
)

// Parse jenkins ajax response in order find the current jenkins build history
func parseBuildHistory(d io.ReadCloser) []*history {
func parseBuildHistory(d io.ReadCloser) []*History {
z := html.NewTokenizer(d)
depth := 0
buildRowCellDepth := -1
builds := make([]*history, 0)
var curBuild *history
builds := make([]*History, 0)
var curBuild *History
for {
tt := z.Next()
switch tt {
Expand Down Expand Up @@ -46,7 +46,7 @@ func parseBuildHistory(d io.ReadCloser) []*history {
if string(tn) == "td" {
if hasCssClass(a, "build-row-cell") {
buildRowCellDepth = depth
curBuild = &history{}
curBuild = &History{}
builds = append(builds, curBuild)
}
}
Expand Down
20 changes: 10 additions & 10 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
package gojenkins

type Executor struct {
Raw *executorResponse
Raw *ExecutorResponse
Jenkins *Jenkins
}
type view struct {
type ViewData struct {
Name string `json:"name"`
URL string `json:"url"`
}
type executorResponse struct {
type ExecutorResponse struct {
AssignedLabels []struct{} `json:"assignedLabels"`
Description interface{} `json:"description"`
Jobs []job `json:"jobs"`
Jobs []InnerJob `json:"jobs"`
Mode string `json:"mode"`
NodeDescription string `json:"nodeDescription"`
NodeName string `json:"nodeName"`
Expand All @@ -35,10 +35,10 @@ type executorResponse struct {
Name string `json:"name"`
URL string `json:"url"`
} `json:"primaryView"`
QuietingDown bool `json:"quietingDown"`
SlaveAgentPort int64 `json:"slaveAgentPort"`
UnlabeledLoad struct{} `json:"unlabeledLoad"`
UseCrumbs bool `json:"useCrumbs"`
UseSecurity bool `json:"useSecurity"`
Views []view `json:"views"`
QuietingDown bool `json:"quietingDown"`
SlaveAgentPort int64 `json:"slaveAgentPort"`
UnlabeledLoad struct{} `json:"unlabeledLoad"`
UseCrumbs bool `json:"useCrumbs"`
UseSecurity bool `json:"useSecurity"`
Views []ViewData `json:"views"`
}
32 changes: 16 additions & 16 deletions jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type BasicAuth struct {
type Jenkins struct {
Server string
Version string
Raw *executorResponse
Raw *ExecutorResponse
Requester *Requester
}

Expand Down Expand Up @@ -76,7 +76,7 @@ func (j *Jenkins) Init() (*Jenkins, error) {
}

// Check Connection
j.Raw = new(executorResponse)
j.Raw = new(ExecutorResponse)
rsp, err := j.Requester.GetJSON("/", j.Raw, nil)

if err != nil {
Expand Down Expand Up @@ -106,7 +106,7 @@ func (j *Jenkins) initLoggers() {
}

// Get Basic Information About Jenkins
func (j *Jenkins) Info() (*executorResponse, error) {
func (j *Jenkins) Info() (*ExecutorResponse, error) {
_, err := j.Requester.Get("/", j.Raw, nil)

if err != nil {
Expand Down Expand Up @@ -209,7 +209,7 @@ func (j *Jenkins) CreateJob(config string, options ...interface{}) (*Job, error)
} else {
return nil, errors.New("Error Creating Job, job name is missing")
}
jobObj := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + qr["name"]}
jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + qr["name"]}
job, err := jobObj.Create(config, qr)
if err != nil {
return nil, err
Expand All @@ -220,15 +220,15 @@ func (j *Jenkins) CreateJob(config string, options ...interface{}) (*Job, error)
// Rename a job.
// First parameter job old name, Second parameter job new name.
func (j *Jenkins) RenameJob(job string, name string) *Job {
jobObj := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + job}
jobObj := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + job}
jobObj.Rename(name)
return &jobObj
}

// Create a copy of a job.
// First parameter Name of the job to copy from, Second parameter new job name.
func (j *Jenkins) CopyJob(copyFrom string, newName string) (*Job, error) {
job := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + copyFrom}
job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + copyFrom}
_, err := job.Poll()
if err != nil {
return nil, err
Expand All @@ -238,14 +238,14 @@ func (j *Jenkins) CopyJob(copyFrom string, newName string) (*Job, error) {

// Delete a job.
func (j *Jenkins) DeleteJob(name string) (bool, error) {
job := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + name}
job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name}
return job.Delete()
}

// Invoke a job.
// First parameter job name, second parameter is optional Build parameters.
func (j *Jenkins) BuildJob(name string, options ...interface{}) (int64, error) {
job := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + name}
job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + name}
var params map[string]string
if len(options) > 0 {
params, _ = options[0].(map[string]string)
Expand Down Expand Up @@ -291,7 +291,7 @@ func (j *Jenkins) GetBuild(jobName string, number int64) (*Build, error) {
}

func (j *Jenkins) GetJob(id string, parentIDs ...string) (*Job, error) {
job := Job{Jenkins: j, Raw: new(jobResponse), Base: "/job/" + strings.Join(append(parentIDs, id), "/job/")}
job := Job{Jenkins: j, Raw: new(JobResponse), Base: "/job/" + strings.Join(append(parentIDs, id), "/job/")}
status, err := job.Poll()
if err != nil {
return nil, err
Expand Down Expand Up @@ -326,7 +326,7 @@ func (j *Jenkins) GetAllNodes() ([]*Node, error) {
// There are only build IDs here,
// To get all the other info of the build use jenkins.GetBuild(job,buildNumber)
// or job.GetBuild(buildNumber)
func (j *Jenkins) GetAllBuildIds(job string) ([]jobBuild, error) {
func (j *Jenkins) GetAllBuildIds(job string) ([]JobBuild, error) {
jobObj, err := j.GetJob(job)
if err != nil {
return nil, err
Expand All @@ -336,8 +336,8 @@ func (j *Jenkins) GetAllBuildIds(job string) ([]jobBuild, error) {

// Get Only Array of Job Names, Color, URL
// Does not query each single Job.
func (j *Jenkins) GetAllJobNames() ([]job, error) {
exec := Executor{Raw: new(executorResponse), Jenkins: j}
func (j *Jenkins) GetAllJobNames() ([]InnerJob, error) {
exec := Executor{Raw: new(ExecutorResponse), Jenkins: j}
_, err := j.Requester.GetJSON("/", exec.Raw, nil)

if err != nil {
Expand All @@ -350,7 +350,7 @@ func (j *Jenkins) GetAllJobNames() ([]job, error) {
// Get All Possible Job Objects.
// Each job will be queried.
func (j *Jenkins) GetAllJobs() ([]*Job, error) {
exec := Executor{Raw: new(executorResponse), Jenkins: j}
exec := Executor{Raw: new(ExecutorResponse), Jenkins: j}
_, err := j.Requester.GetJSON("/", exec.Raw, nil)

if err != nil {
Expand Down Expand Up @@ -391,7 +391,7 @@ func (j *Jenkins) GetArtifactData(id string) (*fingerPrintResponse, error) {
// Returns the list of all plugins installed on the Jenkins server.
// You can supply depth parameter, to limit how much data is returned.
func (j *Jenkins) GetPlugins(depth int) (*Plugins, error) {
p := Plugins{Jenkins: j, Raw: new(pluginResponse), Base: "/pluginManager", Depth: depth}
p := Plugins{Jenkins: j, Raw: new(PluginResponse), Base: "/pluginManager", Depth: depth}
_, err := p.Poll()
if err != nil {
return nil, err
Expand Down Expand Up @@ -425,7 +425,7 @@ func (j *Jenkins) ValidateFingerPrint(id string) (bool, error) {

func (j *Jenkins) GetView(name string) (*View, error) {
url := "/view/" + name
view := View{Jenkins: j, Raw: new(viewResponse), Base: url}
view := View{Jenkins: j, Raw: new(ViewResponse), Base: url}
_, err := view.Poll()
if err != nil {
return nil, err
Expand Down Expand Up @@ -464,7 +464,7 @@ func (j *Jenkins) CreateView(name string, viewType string) (*View, error) {
Error.Println("View Already exists.")
return exists, errors.New("View already exists")
}
view := &View{Jenkins: j, Raw: new(viewResponse), Base: "/view/" + name}
view := &View{Jenkins: j, Raw: new(ViewResponse), Base: "/view/" + name}
endpoint := "/createView"
data := map[string]string{
"name": name,
Expand Down
Loading

0 comments on commit 71a45a7

Please sign in to comment.