ソースを参照

Make missing datacite.yml a fatal startup error

- Check if datacite.yml template has been compiled in to bindata at
startup; fail if not able to load during route setup.
- Rename add datacite function to be more descriptive.
- Add a default commit message.
Achilleas Koutsou 6 年 前
コミット
2774f12812
2 ファイル変更12 行追加9 行削除
  1. 6 1
      cmd/web.go
  2. 6 8
      routes/repo/editor.go

+ 6 - 1
cmd/web.go

@@ -569,6 +569,9 @@ func runWeb(c *cli.Context) error {
 		m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
 			Post(bindIgnErr(form.NewIssue{}), repo.CompareAndPullRequestPost)
 
+		if _, err := bindata.Asset("conf/datacite/datacite.yml"); err != nil {
+			log.Fatal(2, "%v", err)
+		}
 		m.Group("", func() {
 			m.Combo("/_edit/*").Get(repo.EditFile).
 				Post(bindIgnErr(form.EditRepoFile{}), repo.EditFilePost)
@@ -577,7 +580,9 @@ func runWeb(c *cli.Context) error {
 			m.Post("/_preview/*", bindIgnErr(form.EditPreviewDiff{}), repo.DiffPreviewPost)
 			m.Combo("/_delete/*").Get(repo.DeleteFile).
 				Post(bindIgnErr(form.DeleteRepoFile{}), repo.DeleteFilePost)
-			m.Combo("/_add/*").Get(repo.AddFile).Post(bindIgnErr(form.EditRepoFile{}), repo.NewFilePost)
+			// GIN: Add datacite.yml file through the repo web interface
+
+			m.Combo("/_add/*").Get(repo.CreateDatacite).Post(bindIgnErr(form.EditRepoFile{}), repo.NewFilePost)
 			m.Group("", func() {
 				m.Combo("/_upload/*").Get(repo.UploadFile).
 					Post(bindIgnErr(form.UploadRepoFile{}), repo.UploadFilePost)

+ 6 - 8
routes/repo/editor.go

@@ -583,25 +583,23 @@ func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
 	c.Status(204)
 }
 
-func AddFile(c *context.Context) {
-	link := strings.Split(c.Link, "/")
-	name := link[len(link)-1]
+func CreateDatacite(c *context.Context) {
+	dcname := path.Join("conf/datacite/datacite.yml")
 	treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
 
 	c.PageIs("Edit")
 	c.RequireHighlightJS()
 	c.RequireSimpleMDE()
 
-	c.Data["IsJSON"] = markup.IsJSON(name)
-	c.Data["IsYAML"] = markup.IsYAML(name)
-	relName := path.Join("conf", "datacite", name)
-	data, _ := bindata.Asset(relName)
+	c.Data["IsYAML"] = true
+	// safe to ignore error since we check for the asseet at startup
+	data, _ := bindata.Asset(dcname)
 	c.Data["FileContent"] = string(data)
 	c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
 	c.Data["TreeNames"] = treeNames
 	c.Data["TreePaths"] = treePaths
 	c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
-	c.Data["commit_summary"] = ""
+	c.Data["commit_summary"] = "Add information for publishing with DataCite"
 	c.Data["commit_message"] = ""
 	c.Data["commit_choice"] = "direct"
 	c.Data["new_branch_name"] = ""