// GetLatestRepo gets the newest version of an OpenBuildService // repository. func GetLatestRepo(info OpenBuildService) error { var err error if util.FileExists(filepath.Join("repos-obs", info.Repo)) { err = updateRepo(info) } else { err = checkoutRepo(info) } return err }
// GetLatestRepo either clones a new repo or updates an existing one // into the 'repos' directory. func GetLatestRepo(url string) (err error) { var local string local = util.LocalRepoName(url) rd := RepoData{url: url, workingDirectory: "repos-hg", localName: local} if util.FileExists(filepath.Join("repos-hg", local)) { err = updateRepo(rd) } else { err = cloneRepo(rd) } return }
// GetLatestGitRepo either clones a new repo or updates an existing one // into the 'repos' directory. func GetLatestGitRepo(url string, isTest bool) error { var err error var local string if isTest { local = "dummy-git-repo" } else { local = util.LocalRepoName(url) } rd := RepoData{url: url, workingDirectory: "repos", localName: local} if util.FileExists("repos/" + local) { err = updateRepo(rd) } else { err = cloneRepo(rd) } return err }
// Run will handle the functionallity. func run(ctx *cli.Context) error { // Load specified json configuration file configPath := ctx.GlobalString("config") configuration, err := loadConfig(configPath) if err != nil { // if config cant be loaded because default one is used // (set in StringFlag) and is not available, then show the usage. if !ctx.IsSet("config") { cli.ShowAppHelp(ctx) return nil } return cli.NewExitError(err.Error(), 1) } // Get users template selection templateName := ctx.GlobalString("template") var templateData string // Get Template as templateData string templatesPath := os.Getenv(templatesFolderEnv) if templatesPath == "" { // Use asset data, err := Asset(filepath.Join(templateFolderName, templateName)) if err != nil { return cli.NewExitError(err.Error(), 1) } templateData = string(data) } else { // Use template from user defined folder absoluteTemplatePath := filepath.Join(templatesPath, templateName) if !util.FileExists(absoluteTemplatePath) { var s string fmt.Sprintf(s, "Template file %s does not exist\n", absoluteTemplatePath) return cli.NewExitError(s, 1) } data, err := ioutil.ReadFile(absoluteTemplatePath) if err != nil { return cli.NewExitError(err.Error(), 1) } templateData = string(data) } gontrib.PullSources = !ctx.GlobalBool("no-pull") contributions, err := gontrib.ScanContributions(configuration) if err != nil { util.PrintInfo(err.Error(), util.PI_ERROR) return cli.NewExitError(err.Error(), 1) } outputPath := ctx.GlobalString("output") f, err := os.Create(outputPath) if err != nil { return cli.NewExitError(err.Error(), 1) } defer f.Close() writer := bufio.NewWriter(f) fillTemplate(contributions, templateData, writer) if err := writer.Flush(); err != nil { return cli.NewExitError(err.Error(), 1) } util.PrintInfoF("\nReport saved in: %s", util.PI_INFO, outputPath) return nil }