Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to submit for review #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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/[email protected]
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?**
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,3 +60,4 @@ runs:
-d "${{inputs.GITHUB_DIR}}"
-r "${{inputs.DELETE}}"
-p "${{inputs.PUBLISH}}"
-rev "${{inputs.REVIEW}}"
44 changes: 38 additions & 6 deletions dataverse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import argparse
from time import sleep
from os.path import join
Expand Down Expand Up @@ -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 """
Expand All @@ -38,19 +49,25 @@ 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)
check_dataset_lock(num-1)
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
Expand All @@ -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
Expand All @@ -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(",", " ")
Expand Down Expand Up @@ -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,
)