Exemple #1
0
func (p *PublishCommand) Run() error {

	token, err := LoginPrompt(context.Background(), p.Ctx.Client)

	if err != nil {
		fmt.Printf("ERROR: %v\n", err)
		return err
	}

	fmt.Println("Running check")
	if err := NewCheckCommand(p.Ctx).Run(); err != nil {
		p.Fatal(err.Error())
	}

	wrapper, err := common.LoadPackage("")

	if err != nil {
		p.Fatal("Cannot read " + core.PackageFile + ": " + err.Error())
	}

	publisher, err := vcs.CreatePublisher(wrapper.Repository)
	if err != nil {
		p.Fatal("Cannot find VCS: " + err.Error())
	}

	wrapper.Version.Revision, err = publisher.LastCommitRevision()

	if err != nil {
		p.Fatal("Cannot get the last commit SHA1: " + err.Error())
	}

	if err := publisher.ValidateCommit(wrapper.Version.Revision); err != nil {
		p.Fatal(err.Error())
	}

	fmt.Println("Publishing")
	_, err = p.Ctx.Client.Publish(context.Background(), &msg.PublishRequest{
		Token:              token,
		PackageDescription: wrapper.Package,
	})

	if err != nil {
		p.Fatal("ERROR:" + err.Error())
	}

	tag := <-Prompt("Tag release:", "Y/n")
	if len(tag) == 0 || strings.ToLower(string(tag[0])) == "y" {
		publisher.CreateTag("qpm/" + wrapper.Version.Label)
	}

	fmt.Println("SUCCESS!")
	signature := strings.Join([]string{wrapper.Name, wrapper.Version.Label}, "@")
	fmt.Println("Publised package: " + signature)
	fmt.Println("Revision: " + wrapper.Version.Revision)

	return nil
}
Exemple #2
0
func hashRepo(repository *msg.Package_Repository) (string, error) {

	publisher, err := vcs.CreatePublisher(repository)
	if err != nil {
		return "", err
	}

	paths, err := publisher.RepositoryFileList()
	if err != nil {
		return "", err
	}

	return HashPaths(paths)
}
Exemple #3
0
func (ic *InitCommand) Run() error {

	ic.Pkg = &common.PackageWrapper{Package: common.NewPackage()}

	if t, err := vcs.RepoType(); err != nil {
		fmt.Println("WARNING: Could not auto-detect repository type.")
	} else {
		ic.Pkg.Repository.Type = t
	}

	publisher, err := vcs.CreatePublisher(ic.Pkg.Repository)
	if err != nil {
		ic.Error(err)
		return err
	}

	ic.Pkg.Author.Name, _ = publisher.LastCommitAuthorName()
	ic.Pkg.Author.Name, _ = <-Prompt("Your name:", ic.Pkg.Author.Name)

	ic.Pkg.Author.Email, _ = publisher.LastCommitEmail()
	ic.Pkg.Author.Email = <-Prompt("Your email:", ic.Pkg.Author.Email)

	cwd, err := os.Getwd()
	if err != nil {
		ic.Error(err)
		cwd = ""
	} else {
		cwd = filepath.Base(cwd)
	}

	suggestedName := extractReverseDomain(ic.Pkg.Author.Email) + "." + cwd

	ic.Pkg.Name = <-Prompt("Unique package name:", suggestedName)
	ic.Pkg.Version.Label = <-Prompt("Initial version:", ic.Pkg.Version.Label)

	ic.Pkg.Repository.Url, err = publisher.RepositoryURL()
	if err != nil {
		fmt.Println("WARNING: Could not auto-detect repository URL.")
	}

	ic.Pkg.Repository.Url = <-Prompt("Clone URL:", ic.Pkg.Repository.Url)

	filename, _ := ic.findPriFile()
	if len(filename) == 0 {
		filename = ic.Pkg.PriFile()
	}

	license := <-Prompt("License:", "MIT")

	// convert Github style license strings
	license = strings.ToUpper(regexGitHubLicense.ReplaceAllString(license, "_"))

	if licenseType, err := msg.LicenseType_value[license]; !err {
		errMsg := fmt.Sprintf("ERROR: Non-supported license type: %s\n", license)
		fmt.Print(errMsg)
		fmt.Printf("Valid values are:\n")
		for i := 0; i < len(msg.LicenseType_name); i++ {
			fmt.Println("\t" + msg.LicenseType_name[int32(i)])
		}
		return errors.New(errMsg)
	} else {
		ic.Pkg.License = msg.LicenseType(licenseType)
	}

	ic.Pkg.PriFilename = <-Prompt("Package .pri file:", filename)

	if err := ic.Pkg.Save(); err != nil {
		ic.Error(err)
		return err
	}

	bootstrap := <-Prompt("Generate boilerplate:", "Y/n")
	if len(bootstrap) == 0 || strings.ToLower(string(bootstrap[0])) == "y" {
		if err := ic.GenerateBoilerplate(); err != nil {
			return err
		}

		ic.GenerateLicense()
	}
	return nil
}