예제 #1
0
파일: status.go 프로젝트: hhatto/jc
func printJobQueue(url string, dumpFlag bool) {
	b := bytes.NewBufferString(" ")
	queueItems, _ := getQueue(url, dumpFlag)
	b.WriteString(fmt.Sprintf("build queue: %d", len(queueItems)))
	executors, _ := getExecutors(url, dumpFlag)

	b.WriteString(fmt.Sprintf(",  executor: %d/%d", executors.BusyExecutors, executors.TotalExecutors))

	for _, queue := range queueItems {
		b.WriteString(fmt.Sprintf("\n  %s  - %-20s %s",
			nanairo.FgColor("#E0ffff", "✈ ⇥"), queue.Task.Name,
			nanairo.FgColor("#666666", "(in build queue)")))
	}

	if len(executors.ComputerInfos) <= 0 {
		fmt.Println("jenkins invalid state")
		return
	}

	for _, info := range executors.ComputerInfos {
		for _, executor := range info.Executors {
			if executor.Progress < 0 {
				continue
			}
			b.WriteString(fmt.Sprintf("\n  %s  - %-20s %s",
				nanairo.FgColor("#ff6347", "✈ ➟"), executor.Detail.DisplayName,
				nanairo.FgColor("#666666", fmt.Sprintf("(%d/100)", executor.Progress))))
		}
	}
	fmt.Println(b.String())
}
예제 #2
0
파일: job.go 프로젝트: hhatto/jc
func printJobDetail(url string, jobName string, dumpFlag bool) {
	b := bytes.NewBufferString("")
	jobItems, _ := getJobInfo(url, jobName, dumpFlag)

	if len(jobItems) > 0 {
		b.WriteString(fmt.Sprintf("[%s]\n", jobName))
	} else {
		b.WriteString(fmt.Sprintf("'%s' job is not found\n", jobName))
	}

	for cnt, job := range jobItems {
		if cnt >= 5 {
			break
		}
		resultNumber := nanairo.FgColor("#0c0", strconv.Itoa(job.Number))
		if job.Result != "SUCCESS" {
			resultNumber = nanairo.FgColor("#c00", strconv.Itoa(job.Number))
		}
		humanReadableDurationValue := fmt.Sprintf("%ds", job.Duration/1000)
		if job.Duration/1000 >= 60 {
			humanReadableDurationValue = fmt.Sprintf("%dm%ds", job.Duration/1000/60, job.Duration/1000%60)
		}
		b.WriteString(fmt.Sprintf("  [%4s] %s (%6s)\n", resultNumber,
			time.Unix(int64(job.Timestamp)/1000, 0),
			humanReadableDurationValue))
	}

	fmt.Print(b.String())
}
예제 #3
0
파일: jobs.go 프로젝트: hhatto/jc
func jobsCommand(c *cli.Context) {
	targetHost := Config.Get(c.String("name"))
	u, err := url.Parse(targetHost)
	if err != nil {
		log.Fatal(err)
	}
	isViewAccess := c.Args().Present()

	if isViewAccess {
		u.Path = fmt.Sprintf("view/%s", c.Args().First())
	}
	jobs, _ := getJobs(u.String(), c.Bool("dump"))
	if c.Bool("dump") == true || len(jobs) == 0 {
		if isViewAccess {
			fmt.Println(fmt.Sprintf("'%s' view is not exists", c.Args().First()))
		}
		return
	}
	fmt.Println(c.String("name"), "-", targetHost)
	if isViewAccess {
		fmt.Println(fmt.Sprintf("[view:%s]", c.Args().First()))
	}
	for _, job := range jobs {
		// S
		var j = bytes.NewBufferString("  ")
		if job.Color == "blue" {
			j.WriteString(nanairo.FgColor("#0c0", "✔"))
		} else if job.Color == "disabled" {
			j.WriteString(nanairo.FgColor("#666", "✔"))
		} else if job.Color == "blue_anime" {
			j.WriteString(nanairo.FgColor("#0cc", "➟"))
		} else {
			j.WriteString(nanairo.FgColor("#c00", "✔"))
		}
		j.WriteString("  ")

		// W
		if len(job.HealthReport) == 0 {
			j.WriteString(nanairo.FgColor("#aaa", "⁇"))
		} else if job.HealthReport[0].Score >= 80 {
			j.WriteString(nanairo.FgColor("#f90", "☀"))
		} else if job.HealthReport[0].Score >= 20 {
			j.WriteString(nanairo.FgColor("#999", "☁"))
		} else {
			j.WriteString(nanairo.FgColor("#03c", "☂"))
		}

		// Name
		j.WriteString(fmt.Sprintf("  %s", job.Name))

		fmt.Println(j.String())
	}
}