Exemple #1
0
// createJob adds a new job to the database.
func (p *pushCallback) createJob() error {
	if p.shouldRun() == false {
		log.Println("Not adding", p.repositoryURL(), p.branch())
		return nil
	}

	repo := database.GetRepository(p.repositoryURL())

	job := database.CreateJob(
		repo,
		p.branch(),
		p.commit(),
		p.commitURL(),
		p.name(),
		p.email(),
	)

	status := make(chan bool, 1)

	queueJob := runner.QueueJob{
		JobID:  job.ID,
		Status: status,
	}

	queueJob.Enqueue()

	if repo.StatusPR {
		<-status
		job = database.GetJob(job.ID)
		postStatus(job, repo, p.statusURL())
	}

	return nil
}
Exemple #2
0
func (p *pullRequestCallback) isCurrent() bool {
	repo := database.GetRepository(p.repositoryURL())
	response, err := makeRequest("GET", p.PR.URL, repo.AccessKey, nil)

	if err != nil {
		return false
	}

	var pr pullRequest
	err = json.Unmarshal(response, &pr)

	if err != nil {
		return false
	}

	if pr.Head.Commit != p.PR.Head.Commit {
		return false
	}

	if pr.State != "open" {
		return false
	}

	return true
}