|
@@ -98,6 +98,45 @@ func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
|
|
|
if doi := getRepoDOI(c); doi != "" && libgin.IsRegisteredDOI(doi) {
|
|
|
c.Data["DOI"] = doi
|
|
|
}
|
|
|
+
|
|
|
+ c.Data["IsDOIReady"] = isDOIReady(c)
|
|
|
+}
|
|
|
+
|
|
|
+// True if repository is not Private, is not registered, or is registered and
|
|
|
+// has changes.
|
|
|
+func isDOIReady(c *context.Context) bool {
|
|
|
+ dbrepo := c.Repo.Repository
|
|
|
+ gitrepo := c.Repo.GitRepo
|
|
|
+
|
|
|
+ headIsRegistered := func() bool {
|
|
|
+ currentDOI, ok := c.Data["DOI"]
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ headBranch, err := gitrepo.GetHEADBranch()
|
|
|
+ if err != nil {
|
|
|
+ log.Error(2, "Failed to get HEAD branch for repo at %q: %v", gitrepo.Path, err)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ headCommit, err := gitrepo.GetBranchCommitID(headBranch.Name)
|
|
|
+ if err != nil {
|
|
|
+ log.Error(2, "Failed to get commit ID of branch %q for repo at %q: %v", headBranch.Name, gitrepo.Path, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ // if current valid and registered DOI matches the HEAD commit, can't
|
|
|
+ // register again
|
|
|
+ doiCommit, err := gitrepo.GetTagCommitID(currentDOI.(string))
|
|
|
+ if err != nil {
|
|
|
+ log.Error(2, "Failed to get commit ID of tag %q for repo at %q: %v", currentDOI, gitrepo.Path, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Trace("%s ?= %s", headCommit, doiCommit)
|
|
|
+ return headCommit == doiCommit
|
|
|
+ }()
|
|
|
+
|
|
|
+ return !dbrepo.IsPrivate && !headIsRegistered
|
|
|
}
|
|
|
|
|
|
// getRepoDOI returns the DOI for the repository based on the following rules:
|