Commit dd0f2bae authored by Cyril Matthey-Doret's avatar Cyril Matthey-Doret
Browse files

use ingest_token in every command

parent bef28d68
......@@ -16,6 +16,7 @@ import click
from datetime import datetime
import pytz
from teach_utils.common_requests import parse_repo_url, get_project_id
from teach_utils.utils import ingest_token
def validate_iso_date(date: str) -> str:
......@@ -134,17 +135,12 @@ def format_fork_metadata(
)
@click.argument("repo_url", type=str)
@click.option(
"--token",
"--token-path",
type=click.Path(exists=True),
help="Path to a file containing the Gitlab API token. If not provided, you will be prompted for the token.",
)
def main(repo_url, token, deadline=None):
if token is None:
token = click.prompt(
"Please enter your Gitlab API token", hide_input=True, err=True
)
else:
token = open(token).read().strip()
def main(repo_url, token_path, deadline=None):
token = ingest_token(token_path)
# Check for valid deadline format
if deadline is not None:
validate_iso_date(deadline)
......
......@@ -6,6 +6,7 @@ from typing import Dict
import requests
import click
from teach_utils.common_requests import parse_repo_url, get_group_id
from teach_utils.utils import ingest_token
def invite_student_email(
......@@ -24,10 +25,10 @@ def find_email(line: str) -> str:
"""Find and return email address in input string.
Raises an error if none found and only return the first
email if there are more than one.
Examples
--------
>>> find_email('robert,smith,robert.smith@no.where,123')
'robert.smith@no.where'
>>> find_email('mike.rock@yes.no,mrock@yes.no')
......@@ -47,20 +48,15 @@ def find_email(line: str) -> str:
)
@click.argument("group-url")
@click.option(
"--token",
"--token-path",
type=click.Path(exists=True),
help="Path to a file containing the Gitlab API token. If not provided, you will be prompted for the token.",
)
def main(emails_file, group_url, token):
def main(emails_file, group_url, token_path):
"""
Send invitations to join input gitlab group to all emails in the emails_file.
The file should have one email per line."""
if token is None:
token = click.prompt(
"Please enter your Gitlab API token", hide_input=True, err=True
)
else:
token = open(token).read().strip()
token = ingest_token(token_path)
header = {"PRIVATE-TOKEN": token}
# Recover the email on each line, in case there are multiple columns
......
......@@ -8,6 +8,7 @@ import requests
import pandas as pd
import click
from teach_utils.common_requests import get_group_id, parse_group_url
from teach_utils.utils import ingest_token
def create_student_group(
......@@ -52,23 +53,17 @@ def generate_student_code(first_name: str, last_name: str) -> str:
@click.argument("student_table")
@click.argument("parent_url")
@click.option(
"--token",
"--token-path",
type=click.Path(exists=True),
help="Path to a file containing the Gitlab API token. If not provided, you will be prompted for the token.",
)
def main(student_table, parent_url, token):
def main(student_table, parent_url, token_path):
"""Given a parent-group URL and a CSV file of students exported from Moodle,
create one private subgroup for each student in the parent group and invite students
in their personal group. The student table must contain columns: "Email address", "First name"
and "Surname"
"""
if token is None:
token = click.prompt(
"Please enter your Gitlab API token", hide_input=True, err=True
)
else:
token = open(token).read().strip()
token = ingest_token(token_path)
header = {"PRIVATE-TOKEN": token}
students = pd.read_csv(student_table)
......
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