From 5236715c78cd1d116346e7b7e168d4e3dc5ce232 Mon Sep 17 00:00:00 2001 From: Edoardo Costantini Date: Mon, 18 Nov 2024 14:22:49 +0100 Subject: [PATCH 1/5] feature: add submit for review option --- dataverse.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dataverse.py b/dataverse.py index 7fac891..77f1f1a 100644 --- a/dataverse.py +++ b/dataverse.py @@ -26,6 +26,11 @@ 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_ @@ -102,3 +107,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", + payload=params, + headers=headers, + ) From 6358e1577a60f01d65a19a98a6f8ec53a14fbfeb Mon Sep 17 00:00:00 2001 From: Edoardo Costantini Date: Mon, 18 Nov 2024 14:35:19 +0100 Subject: [PATCH 2/5] feature: allow github action to recognize the review parameter --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) 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}}" From fbca318e8b190a89f84f324896183588bb036b79 Mon Sep 17 00:00:00 2001 From: Edoardo Costantini Date: Mon, 18 Nov 2024 14:36:15 +0100 Subject: [PATCH 3/5] docs: add description of REVIEW options --- CONTRIBUTING.md | 6 ++++++ README.md | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) 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?** From 2d3c0ff757a19a9e0ef19a4f942f6dc31bc5326a Mon Sep 17 00:00:00 2001 From: Edoardo Costantini Date: Mon, 18 Nov 2024 14:48:30 +0100 Subject: [PATCH 4/5] fix: set params to payload instead of the opposite --- dataverse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataverse.py b/dataverse.py index 77f1f1a..c786f68 100644 --- a/dataverse.py +++ b/dataverse.py @@ -76,7 +76,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(",", " ") @@ -117,6 +117,6 @@ def check_dataset_lock(num): } response = requests.post( dataverse_server + "/api/datasets/:persistentId/submitForReview", - payload=params, + params=payload, headers=headers, ) From 404d541accc6b0c72a1b380e9fabe8d43db2ea33 Mon Sep 17 00:00:00 2001 From: Edoardo Costantini Date: Mon, 18 Nov 2024 17:10:52 +0100 Subject: [PATCH 5/5] fix: stop process if dataset is under review --- dataverse.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/dataverse.py b/dataverse.py index c786f68..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 @@ -35,6 +36,11 @@ def parse_arguments(): 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 """ @@ -43,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) @@ -56,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 @@ -65,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