Skip to content

Commit 82f4dcf

Browse files
rhansenottok
authored andcommitted
Ignore /vN major version suffix when populating Upstream-Name
1 parent 1d3ad90 commit 82f4dcf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

template.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log"
66
"os"
77
"path/filepath"
8+
"regexp"
89
"sort"
910
"strings"
1011
"time"
@@ -258,9 +259,19 @@ func writeDebianCopyright(dir, gopkg string, vendorDirs []string, hasGodeps bool
258259
linebreak = "\n"
259260
}
260261

262+
// Determine a reasonable default for the upstream project's name. If the
263+
// module is named something like example.com/foo/bar, then use the final
264+
// component "bar" as the project name. But if the module name has a major
265+
// version suffix, such as example.com/foo/bar/v2, then strip off the suffix
266+
// before taking the final component.
267+
upstreamName := filepath.Base(gopkg)
268+
if regexp.MustCompile(`^v\d+$`).MatchString(upstreamName) {
269+
upstreamName = filepath.Base(filepath.Dir(gopkg))
270+
}
271+
261272
fmt.Fprintf(f, "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n")
262273
fmt.Fprintf(f, "Source: %s\n", getHomepageForGopkg(gopkg))
263-
fmt.Fprintf(f, "Upstream-Name: %s\n", filepath.Base(gopkg))
274+
fmt.Fprintf(f, "Upstream-Name: %s\n", upstreamName)
264275
fmt.Fprintf(f, "Upstream-Contact: TODO\n")
265276
if len(vendorDirs) > 0 || hasGodeps {
266277
fmt.Fprintf(f, "Files-Excluded:\n")

0 commit comments

Comments
 (0)