Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Commit e18c0aac authored by Andreas Wagner's avatar Andreas Wagner
Browse files

Fix #12 #15 #22.

parent 8664c7b7
......@@ -31,7 +31,7 @@ When used via its file upload API endpoint (instead of the webhook listener), th
- if the file has not changed, the response will just be the zenodo DOI that has been created
<img align="left" style="margin-right:10px;" src="https://upload.wikimedia.org/wikipedia/commons/d/d1/Emblem-notice.svg"/>
Note that, since the XPath library that this service uses only supports basic XPath functions, you cannot really parse or manipulate the values via configuration settings. This means that you have to use some of zenodo's controlled vocabulary in your TEI markup! For instance, the names of licenses or if editor roles in your TEI files are expected to be compatible with zenodo. You could, for example, use the `@n`-attribute of TEI's `&lt;editor&gt;` element to hold the required string like "cc-by" or use zenodo's controlled vocabulary for contributor types to specify the TEI `&lt;editor&gt;`'s `@role`-attribute...
Note that, since the XPath library that this service uses only supports basic XPath functions, you cannot really parse or manipulate the values via configuration settings. This means that you have to use some of zenodo's controlled vocabulary in your TEI markup! For instance, the names of licenses or if editor roles in your TEI files are expected to be compatible with zenodo. You could, for example, use the `@n`-attribute of TEI's `&lt;licence&gt;` element to hold the required string like "cc-by" or use zenodo's controlled vocabulary for contributor types (ContactPerson, DataCollector, DataCurator, DataManager, Distributor, Editor, Funder, HostingInstitution, Producer, ProjectLeader, ProjectManager, ProjectMember, RegistrationAgency, RegistrationAuthority, RelatedPerson, Researcher, ResearchGroup, RightsHolder, Supervisor, Sponsor, WorkPackageLeader, Other) to specify one of the required values in the TEI `&lt;editor&gt;`'s `@role`-attribute... (You can learn about required fields and zenodo's controlled vocabularies at [zenodo's API page](https://developers.zenodo.org/#representation).)
## Installation \& Setup
......
......@@ -551,11 +551,17 @@ func PutFile(myDeposit *tei2zenodo.Deposit, conf *tei2zenodo.Config, c *gin.Cont
// 1. remember old commit SHA (myDeposit.CommitSHA)
ownerName := strings.Split(githubConf.Repo, "/")[0]
repoName := strings.Split(githubConf.Repo, "/")[1]
oldCommitSHA := myDeposit.CommitSHA
log.Tracef(" Commit to base the new commit on (from internal myDeposit object): %s", oldCommitSHA)
branch := githubConf.Branch
ref, _, GRErr := client.Git.GetRef(c, ownerName, repoName, "refs/heads/"+branch)
if GRErr != nil {
log.Errorf("Problem getting branch reference: %v ...", GRErr)
return "", tei2zenodo.NewError("errGHProcessing", fmt.Sprintf("problem getting branch reference: %s", GRErr.Error()), 500, GRErr)
}
oldCommitSHA := ref.Object.SHA
log.Tracef(" Commit to base the new commit on (head of branch %s): %s", branch, oldCommitSHA)
// 2. get old commit and its tree (=baseTree)
oldCommit, _, OCErr := client.Git.GetCommit(c, ownerName, repoName, oldCommitSHA)
oldCommit, _, OCErr := client.Git.GetCommit(c, ownerName, repoName, *oldCommitSHA)
if OCErr != nil {
log.Errorf("Problem getting old commit: %v ...", OCErr)
return "", tei2zenodo.NewError("errGHProcessing", fmt.Sprintf("problem getting old commit: %s", OCErr.Error()), 500, OCErr)
......@@ -612,14 +618,6 @@ func PutFile(myDeposit *tei2zenodo.Deposit, conf *tei2zenodo.Config, c *gin.Cont
log.Tracef(" New commit object: %v", *newCommit)
// 5. update heads/{branch} to point to new commit SHA
branch := githubConf.Branch
ref, _, GRErr := client.Git.GetRef(c, ownerName, repoName, "refs/heads/"+branch)
if GRErr != nil {
log.Errorf("Problem getting branch reference: %v ...", GRErr)
return "", tei2zenodo.NewError("errGHProcessing", fmt.Sprintf("problem getting branch reference: %s", GRErr.Error()), 500, GRErr)
}
log.Tracef(" Old ref object: %v", *ref)
ref.Object.SHA = newCommit.SHA
_, _, URErr := client.Git.UpdateRef(c, ownerName, repoName, ref, false)
if URErr != nil {
......
......@@ -393,7 +393,7 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
}
// Upload file back to github
_, GPFErr := github.PutFile(&myDeposit, &conf, c)
newCommitSHA, GPFErr := github.PutFile(&myDeposit, &conf, c)
if GPFErr != nil {
log.Errorf("Error putting file to github: %v", GPFErr)
AbortMsg(500, tei2zenodo.NewError("errPutFile", fmt.Sprintf("problem putting file to github: %v", f), 500, GPFErr), c)
......@@ -401,6 +401,8 @@ func SetupRoutes(conf tei2zenodo.Config) *gin.Engine {
}
log.Printf(" Successfully processed file %s (DOI %s, github SHA %s).", myDeposit.Filename, myDeposit.DepositDOI, myDeposit.CommitSHA)
myDeposit.CommitSHA = newCommitSHA
DOIs = append(DOIs, myDeposit.DOIURL)
SHAs = append(SHAs, "https://api.github.com/repos/"+conf.Git.Repo+"/commits/"+myDeposit.CommitSHA)
}
......
......@@ -424,7 +424,7 @@ func MixinDOI(r io.Reader, doi string, c *tei2zenodo.Config) (string, error) {
chlstElmnt := rdElmnt.FindElement("listChange")
chgElmnt := etree.NewElement("change")
chgElmnt.CreateAttr("when", currentTime.Format("2006-01-02"))
chgText := chgElmnt.CreateText(fmt.Sprintf("Replaced DOI from %s to %s (automatically changed by tei2zenodo service).", oldDoi, doi))
chgText := chgElmnt.CreateText(fmt.Sprintf("Updated DOI from %s to %s (automatically changed by tei2zenodo service).", oldDoi, doi))
if chgText == nil {
log.Errorf("Problem creating text for change entry")
return "", tei2zenodo.NewError("errParse", fmt.Sprintf("problem creating text for change entry"), 500, nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment