Exemple #1
0
func Up(rp *repository.Repository, bmp string) {
	var err error

	lt, err := rp.GetLastTag()
	if err != nil {
		log.Fatal(err)
	}

	log.Debugf("Current tag is: %s", lt.Name)

	var nxt string
	switch string(bmp) {
	case Major:
		nxt, err = semver.GetNextMajorVersion(lt.Name)
		if err != nil {
			log.Fatal(err)
		}
		break
	case Minor:
		nxt, err = semver.GetNextMinorVersion(lt.Name)
		if err != nil {
			log.Fatal(err)
		}
		break
	case Patch:
		nxt, err = semver.GetNextPatchVersion(lt.Name)
		if err != nil {
			log.Fatal(err)
		}
		break
	}

	log.Debugf("Next tag is: %s", nxt)

	// Generate a codename
	codename, err := codename.Get(codename.Sanitized)
	if err != nil {
		log.Fatal(err)
	}
	log.Debugf("The generated codename is: %s", codename)

	msg, err := message.New(
		message.Chore,
		"release",
		fmt.Sprintf("v%s codename(%s)", nxt, codename),
	)
	if err != nil {
		log.Fatal(err)
	}

	err = rp.CreateAndPushTag(nxt, msg.String())
	if err != nil {
		log.Fatal(err)
	}
	log.Infof("The tag %s has been successfully pushed", nxt)
}
Exemple #2
0
// Generate will lookup the commits for the given tag and create a CHANGELOG.md file in the current path.
func Generate(rp *repository.Repository, tag string, appName string, outputFile string) {
	var err error
	var tg repository.Tag

	if tag != "" {
		tg, err = rp.GetTag(tag)
	} else {
		tg, err = rp.GetLastTag()
	}

	if err != nil {
		log.Fatal(err)
	}

	cmts, err := rp.GetCommitListForTag(tg)
	if err != nil {
		log.Fatal(err)
	}

	ms, err := message.GetMessageGroup(cmts)
	if err != nil {
		log.Fatal(err)
	}

	url, err := rp.GetOriginURL()
	if err != nil {
		log.Fatal(err)
	}

	output, err := getFilledTemplate(pongo2.Context{
		"appName":       appName,
		"version":       tg.Name,
		"message_group": ms,
		"url":           url,
	}, templateFile)
	if err != nil {
		log.Fatal(err)
	}

	fileInfo, err := os.Stat(outputFile)
	if err != nil {
		log.Fatal(err)
	}

	if fileInfo.IsDir() {
		if outputFile[len(outputFile)-1:] != "/" {
			outputFile += string(os.PathSeparator)
		}
		outputFile += changelogFile
	}

	err = ioutil.WriteFile(outputFile, output, 0644)
	if err != nil {
		log.Fatal(err)
	}

	log.Infof("%s has been successfully created!", outputFile)
}