Пример #1
0
func createTag(gitRepo *git.Repository, rel *Release) error {
	// Only actual create when publish.
	if !rel.IsDraft {
		if !gitRepo.IsTagExist(rel.TagName) {
			commit, err := gitRepo.GetCommitOfBranch(rel.Target)
			if err != nil {
				return err
			}

			if err = gitRepo.CreateTag(rel.TagName, commit.Id.String()); err != nil {
				return err
			}
		} else {
			commit, err := gitRepo.GetCommitOfTag(rel.TagName)
			if err != nil {
				return err
			}

			rel.NumCommits, err = commit.CommitsCount()
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Пример #2
0
// CreateRelease creates a new release of repository.
func CreateRelease(gitRepo *git.Repository, rel *Release) error {
	isExist, err := IsReleaseExist(rel.RepoId, rel.TagName)
	if err != nil {
		return err
	} else if isExist {
		return ErrReleaseAlreadyExist
	}

	if !gitRepo.IsTagExist(rel.TagName) {
		_, stderr, err := com.ExecCmdDir(gitRepo.Path, "git", "tag", rel.TagName, "-m", rel.Title)
		if err != nil {
			return errors.New(stderr)
		}
	} else {
		commit, err := gitRepo.GetCommitOfTag(rel.TagName)
		if err != nil {
			return err
		}

		rel.NumCommits, err = commit.CommitsCount()
		if err != nil {
			return err
		}
	}

	rel.LowerTagName = strings.ToLower(rel.TagName)
	_, err = orm.InsertOne(rel)
	return err
}