Exemplo n.º 1
0
func (r *Bitbucket) Adapt(p *http.Request, c *config.Config) (*scm.Push, error) {
	if err := json.Unmarshal([]byte(p.FormValue("payload")), r); err != nil {
		log.Println(err)
		return nil, err
	}

	var m scm.Push
	path := r.Repository.Absolute_url
	m.Repository = &scm.Repository{
		Url:  r.Canon_url + path[:len(path)-1], // remove trailing slash
		Name: r.Repository.Name,
	}

	// search if any commit was made to the branch specified in the config
	if repo, ok := c.Repositories[m.Repository.Url]; ok {
		m.Repository.Path = repo.Path
		m.Repository.Owner = &scm.Owner{
			Name:  repo.Owner.Name,
			Email: repo.Owner.Email,
		}
		for _, commit := range r.Commits {
			if commit.Branch == repo.Ref {
				m.Ref = commit.Branch
				m.After = commit.Raw_node
				return &m, nil
			}
		}
	}
	return nil, UnknownRepoError{
		msg: "unknown repo " + path + " or no commit to relevant ref",
	}
}
Exemplo n.º 2
0
func (r *Github) Adapt(p *http.Request, c *config.Config) (*scm.Push, error) {
	if err := json.Unmarshal([]byte(p.FormValue("payload")), r); err != nil {
		log.Println(err)
		return nil, err
	}

	var m scm.Push
	if repo, ok := c.Repositories[r.Repository.Url]; ok && repo.Ref == r.Ref {
		m.Repository = r.Repository
		m.Repository.Path = repo.Path
		m.After = r.After
		m.Ref = r.Ref
		m.Commits = r.Commits
	} else {
		return nil, UnknownRepoError{
			msg: "unknown repo " + r.Repository.Name + " or ref " + r.Ref,
		}
	}
	return &m, nil
}