示例#1
0
文件: git.go 项目: compotlab/synopsis
func (git *Git) getComposerInformation() (packages.Composer, error) {
	cmd := exec.Command("git", "show", git.Reference+":composer.json")
	cmd.Dir = git.RepoDir

	out, err := cmd.CombinedOutput()
	if err != nil {
		return packages.Composer{}, fmt.Errorf("git show %s. %s", git.Reference+":composer.json", err)
	}

	co := packages.Composer{}

	err = json.Unmarshal(out, &co)
	if err != nil {
		return packages.Composer{}, err
	}

	if co.Time == "" {
		cmd = exec.Command("git", "log", "-1", "--format=%at", git.Reference)
		cmd.Dir = git.RepoDir

		out, err := cmd.CombinedOutput()
		if err != nil {
			return packages.Composer{}, fmt.Errorf("git log -1 --format. %s", err)
		}

		t, _ := strconv.ParseInt(strings.TrimSpace(string(out)), 10, 64)
		co.Time = time.Unix(t, 0).String()
	}

	git.Source = map[string]string{
		"type":      "git",
		"url":       git.URL,
		"reference": git.Reference,
	}

	co.Source = git.Source
	co.Version = git.Version
	co.VersionNormalized = git.VersionNormalized

	return co, nil
}
示例#2
0
// Compress make archive from repository branch
func (repo *Repository) Compress(config *Config, d driver.Driver, p *packages.Composer) error {
	// Prepare path and archive path
	gd := &download.Git{
		Name:    p.Name,
		Version: p.Version,
		URL:     repo.URL,
		Source:  p.Source,
		DistDir: config.DistDir,
	}
	gd.Prepare()
	// Prepare compression
	cz := compress.Zip{
		SourcePath: gd.SourcePath,
	}
	cz.Prepare()
	// Run download
	if !gd.PathExist && !cz.IsExist {
		err := gd.Run()
		if err != nil {
			return err
		}
	}
	// Run compression
	if gd.PathExist && !cz.IsExist {
		err := cz.Run()
		if err != nil {
			return err
		}
	}

	if cz.IsExist {
		host := config.File.Homepage
		if config.File.Archive.PrefixURL != "" {
			host = config.File.Archive.PrefixURL
		}

		p.Dist = map[string]string{
			"type":      cz.Format,
			"url":       host + "/" + path.Join(config.File.Archive.Directory, strings.Replace(cz.TargetPath, gd.DistDir, "", -1)),
			"reference": d.GetReference(),
			"shasum":    hashFile(cz.TargetPath),
		}
	}

	return nil
}