Skip to content

Commit c0733c2

Browse files
committed
Add cgit description support
Make the cgit web UI look a little more nice.
1 parent 80daada commit c0733c2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ require (
1010
gopkg.in/src-d/go-git.v4 v4.8.1
1111
gopkg.in/yaml.v2 v2.2.2
1212
)
13+
14+
go 1.13

main.go

+19
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (r GithubConfig) toRepos(c Config) []repo {
216216
Username: r.Username,
217217
CgitSection: r.Username,
218218
CgitOwner: r.Username,
219+
Description: "[read only] github mirror of " + url,
219220
}
220221

221222
// Need to add support here for using different kinds of urls but currently
@@ -472,6 +473,24 @@ func cgitMetadataOperation(r repo) error {
472473
if r.Extras != (Extras{}) {
473474
config.SetOption("cgit", "", "owner", r.Extras.CgitOwner)
474475
config.SetOption("cgit", "", "section", r.Extras.CgitSection)
476+
477+
if r.Extras.Description != "" {
478+
// Write out a description for cgit web interface
479+
cgitDescriptionFile, err := os.OpenFile(path.Join(r.Path, "description"), os.O_RDWR|os.O_CREATE, 0644)
480+
if err != nil {
481+
return errors.New("Unable to read this repos git config file : " + err.Error())
482+
}
483+
484+
_, err = cgitDescriptionFile.Seek(0, 0)
485+
if err != nil {
486+
return errors.New("Unable to seek to the start of the description file before writing it out : " + err.Error())
487+
}
488+
489+
_, err = cgitDescriptionFile.Write([]byte(r.Extras.Description))
490+
if err != nil {
491+
return errors.New("Unable to write to description file : " + err.Error())
492+
}
493+
}
475494
}
476495

477496
encoder := gitconfig.NewEncoder(gitConfigFile)

0 commit comments

Comments
 (0)