diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 35950d6..7c799ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,6 +47,12 @@ The script will upload everything from **the helper `repo` folder** to the `DATA python dataverse.py 9s3-7d46-hd https://demo.dataverse.org/ doi:10.70122/FK2/LVUADQ user/my-repo -p TRUE ``` +- To upload files and submit the data record for review: + +``` +python dataverse.py 9s3-7d46-hd https://demo.dataverse.org/ doi:10.70122/FK2/LVUADQ user/my-repo -p FALSE -rev TRUE +``` + - To upload files from a single folder, use: ``` diff --git a/README.md b/README.md index e7ac2ac..6b94f30 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ To use this action, you will need the following input parameters: | `GITHUB_DIR` | No | Use `GITHUB_DIR` if you would like to upload files from only one or more subdirectories in your GitHub repository (i.e., `data/`, `plots/`). | | `DELETE` | No | Can be `True` or `False` (by default `True`) depending on whether all files should be deleted in the dataset on Dataverse before upload. | | `PUBLISH` | No | Can be `True` or `False` (by default `False`) depending on whether you'd like to automatically create a new version of the dataset upon upload. If `False`, the uploaded dataset will be a `DRAFT`. | +| `REVIEW` | No | Can be `True` or `False` (by default `False`) depending on whether you'd like to automatically submit the dataset for review upon upload. If `True`, the uploaded dataset will be a `In Review`. | ## Usage @@ -109,6 +110,22 @@ steps: PUBLISH: True ``` +If you would like the action to submit the dataset for review instead: + +``` +steps: + - name: Send repo to Dataverse + uses: IQSS/dataverse-uploader@v1.6 + with: + DATAVERSE_TOKEN: ${{secrets.DATAVERSE_TOKEN}} + DATAVERSE_SERVER: https://demo.dataverse.org + DATAVERSE_DATASET_DOI: doi:10.70122/FK2/LVUA + GITHUB_DIR: data + DELETE: False + PUBLISH: False + REVIEW: True +``` + ## Q&A 1. **If you change the content of your GitHub repository, are the changes synchronized in Dataverse? Otherwise, is it possible to synchronize them automatically?** diff --git a/action.yml b/action.yml index 151c42f..a752935 100644 --- a/action.yml +++ b/action.yml @@ -27,6 +27,10 @@ inputs: required: false description: "publish after upload" default: 'false' + REVIEW: + required: false + description: "submit for review after upload" + default: 'false' runs: using: "composite" @@ -56,3 +60,4 @@ runs: -d "${{inputs.GITHUB_DIR}}" -r "${{inputs.DELETE}}" -p "${{inputs.PUBLISH}}" + -rev "${{inputs.REVIEW}}" diff --git a/dataverse.py b/dataverse.py index 7fac891..4bf56b9 100644 --- a/dataverse.py +++ b/dataverse.py @@ -1,3 +1,4 @@ +import sys import argparse from time import sleep from os.path import join @@ -26,10 +27,20 @@ def parse_arguments(): "-p", "--publish", help="Publish a new dataset version after upload.", \ choices=('True', 'TRUE', 'true', 'False', 'FALSE', 'false'), \ default='false') + parser.add_argument( + "-rev", "--review", help="Submit the dataset for review after upload.", + choices=("True", "TRUE", "true", "False", "FALSE", "false"), + default="false", + ) args_ = parser.parse_args() return args_ +def extract_lock(): + """ Extracts the lock information for the dataset""" + query_str = dataverse_server + "/api/datasets/" + str(dataset_dbid) + "/locks/" + locks = requests.get(query_str, auth=(token, "")) + return locks def check_dataset_lock(num): """ Gives Dataverse server more time for upload """ @@ -38,12 +49,9 @@ def check_dataset_lock(num): str(dataset_dbid) + '\nTry again later!') return - query_str = dataverse_server + \ - '/api/datasets/' + str(dataset_dbid) + '/locks/' - resp_ = requests.get(query_str, auth = (token, "")) - locks = resp_.json()['data'] + locks_data = locks.json()["data"] - if bool(locks): + if bool(locks_data): print('Lock found for dataset id ' + \ str(dataset_dbid) + '\n... sleeping...') sleep(2) @@ -51,6 +59,15 @@ def check_dataset_lock(num): return +def stop_if_dataset_under_review(): + if "InReview" in locks.text: + sys.exit( + "InReview lock found for dataset id " + + str(dataset_dbid) + + ". A dataset under review cannot be modified." + ) + + if __name__ == '__main__': args = parse_arguments() token = args.token @@ -60,6 +77,8 @@ def check_dataset_lock(num): dataset = api.get_dataset(args.doi) files_list = dataset.json()['data']['latestVersion']['files'] dataset_dbid = dataset.json()['data']['id'] + locks = extract_lock() + stop_if_dataset_under_review() if args.remove.lower() == 'true': # the following deletes all the files in the dataset @@ -71,7 +90,7 @@ def check_dataset_lock(num): delete_api + str(fileid), \ auth = (token , "")) - # check if there is a list of dirs to upload + # check if there is a list of dirs to upload paths = ['repo'] if args.dir: dirs = args.dir.strip().replace(",", " ") @@ -102,3 +121,16 @@ def check_dataset_lock(num): if args.publish.lower() == 'true': # publish updated dataset resp = api.publish_dataset(args.doi, release_type="major") + + if args.review.lower() == "true": + headers = { + "X-Dataverse-key": token, + } + payload = { + "persistentId": args.doi, + } + response = requests.post( + dataverse_server + "/api/datasets/:persistentId/submitForReview", + params=payload, + headers=headers, + )