diff --git a/main.go b/main.go index 4c22c0e..c52be1b 100644 --- a/main.go +++ b/main.go @@ -105,6 +105,7 @@ type highlightCategory struct { type release struct { ProjectName string `toml:"project_name"` GithubRepo string `toml:"github_repo"` + SubPath string `toml:"sub_path"` Commit string `toml:"commit"` Previous string `toml:"previous"` PreRelease bool `toml:"pre_release"` @@ -247,6 +248,10 @@ This tool should run from the root of the project repository for a new release. } logrus.Infof("Welcome to the %s release tool...", r.ProjectName) + if r.SubPath != "" { + gitSubpaths = append(gitSubpaths, r.SubPath) + } + mailmapPath, err := filepath.Abs(".mailmap") if err != nil { return fmt.Errorf("failed to resolve mailmap: %w", err) @@ -289,13 +294,13 @@ This tool should run from the root of the project repository for a new release. }) logrus.Infof("creating new release %s with %d new changes...", tag, len(changes)) - current, err := parseDependencies(r.Commit) + current, err := parseDependencies(r.Commit, r.SubPath) if err != nil { return err } overrideDependencies(current, r.OverrideDeps) - previous, err := parseDependencies(r.Previous) + previous, err := parseDependencies(r.Previous, r.SubPath) if err != nil { return err } diff --git a/util.go b/util.go index 75826b7..970d9f0 100644 --- a/util.go +++ b/util.go @@ -66,11 +66,22 @@ func parseTag(path string) string { return strings.TrimSuffix(filepath.Base(path), ".toml") } -func parseDependencies(commit string) ([]dependency, error) { +func parseDependencies(commit, subpath string) ([]dependency, error) { rd, err := fileFromRev(commit, vendorConf) if err == nil { return parseVendorConfDependencies(rd) } + // Look for go module at subpath if provided + if subpath != "" { + rd, err = fileFromRev(commit, filepath.Join(subpath, modulesTxt)) + if err == nil { + return parseModulesTxtDependencies(rd) + } + rd, err = fileFromRev(commit, filepath.Join(subpath, goMod)) + if err == nil { + return parseGoModDependencies(rd) + } + } rd, err = fileFromRev(commit, modulesTxt) if err == nil { return parseModulesTxtDependencies(rd) @@ -451,6 +462,7 @@ func fileFromRev(rev, file string) (io.Reader, error) { } var gitConfigs = map[string]string{} +var gitSubpaths = []string{} func git(args ...string) ([]byte, error) { var gitArgs []string @@ -458,6 +470,10 @@ func git(args ...string) ([]byte, error) { gitArgs = append(gitArgs, "-c", fmt.Sprintf("%s=%s", k, v)) } gitArgs = append(gitArgs, args...) + if len(gitSubpaths) > 0 && len(args) > 0 && args[0] == "log" { + gitArgs = append(gitArgs, "--show-pulls", "--") + gitArgs = append(gitArgs, gitSubpaths...) + } o, err := exec.Command("git", gitArgs...).CombinedOutput() if err != nil { return nil, fmt.Errorf("%s: %s", err, o)