Commit 952b1d18 authored by Dimitri Podborski's avatar Dimitri Podborski
Browse files

Merge branch 'refactoring' into 'master'

release 1.4

Closes #197 and #199

See merge request !5
parents 183bbcbd 4d1a3662
...@@ -46,6 +46,11 @@ Temporary Items ...@@ -46,6 +46,11 @@ Temporary Items
# Local History for Visual Studio Code # Local History for Visual Studio Code
.history/ .history/
####################################
# IntelliJ
####################################
.idea/*
#################################### ####################################
# Python # Python
#################################### ####################################
......
...@@ -51,32 +51,29 @@ Below are a few examples: ...@@ -51,32 +51,29 @@ Below are a few examples:
1. Open issues based on the information provided in a CSV file: 1. Open issues based on the information provided in a CSV file:
e.g.: `python systems.py -o --csv Contribs.csv` e.g.: `python systems.py -o --csv Contribs.csv`
2. Open issues based on CLI options: 2. Open issues based on CLI options:
e.g.: `python systems.py -o -m 55958,55959,56121 -p FileFormat/CENC --meeting 133` e.g.: `python systems.py -o -m 55958,55959,56121 -p http://... --meeting 133`
3. Generate an output document based on the information provided in a CSV file. Use a template as a basis (`--template` is optional): 3. Generate an output document based on the information provided in a CSV file. Use a template as a basis (`--template` is optional):
e.g.: `python systems.py -d --csv Contribs.csv --template template.docx` e.g.: `python systems.py -d --csv Contribs.csv --template template.docx`
4. Close issues based on the information provided in a CSV file: 4. Close issues based on the information provided in a CSV file:
e.g.: `python systems.py -c --csv Contribs.csv` e.g.: `python systems.py -c --csv Contribs.csv`
5. Close issues based on CLI options: 5. Close issues based on CLI options:
e.g.: `python systems.py -c -m m55958,m55959,m56121 -p FileFormat/CENC --meeting 133` e.g.: `python systems.py -c -m m55958,m55959,m56121 -p http://... --meeting 133`
6. Print information about input documents on MDMS and GitLab: 6. Print information about input documents on MDMS and GitLab:
e.g.: `python systems.py -l -m m55958,m55959,m56121 -p FileFormat/CENC --meeting 133` e.g.: `python systems.py -l -m m55958,m55959,m56121 -p http://... --meeting 133`
The CSV file must have a header row with the folowing entries: The CSV file must have a header row with the folowing entries:
- **Number** - MPEG document number with entries like `m12345` - **Number** - MPEG document numbers
- To determine which GitLab project needs to be used make sure that your CSV file has either: - **Project URL** - a full URL to your GitLab project
- **Project URL** - a full URL to your GitLab project (*recommended*) - **Close issue** - (optional) if you want to close multiple issues at once. Supported values are `0`, `1`, `TRUE`, `FALSE`, `true` and `false`.
- or **Sub Group** and **Project Name** - two last elements of the Project URL. (non-case-sensitive)
e.g.: http://mpegx.int-evry.fr/software/MPEG/Systems/PCC-SYS/V-PCC → `Sub Group=PCC-SYS`, `Project Name=V-PCC`.
e.g.: http://mpegx.int-evry.fr/software/MPEG/Systems/FileFormat/isobmff → `Sub Group=FileFormat`, `Project Name=ISOBMFF`
- **Close issue** - is required if you want to close multiple issues at once. Supported values are `0`, `1`, `TRUE`, `FALSE`, `true` and `false`.
The example CSV below has both `Project URL` and (`Sub Group` with `Project Name`) but you can also have one of these in your CSV. The CSV delimiter is determined automatically. The CSV delimiter is determined automatically. The order of columns does not matter. CSV file example:
```csv ```csv
Number;Title;Project URL;Sub Group;Project Name Number;Whatever column;Project URL
m55958;On item encryption;http://mpegx.int-evry.fr/software/MPEG/Systems/FileFormat/CENC;FileFormat;CENC m55958;On item encryption;http://mpegx.int-evry.fr/software/MPEG/Systems/FileFormat/CENC
m55959;On multi-key encryption;http://mpegx.int-evry.fr/software/MPEG/Systems/FileFormat/CENC;FileFormat;CENC m55959;On multi-key encryption;http://mpegx.int-evry.fr/software/MPEG/Systems/FileFormat/CENC
...
``` ```
## 3. generate_ballot_issues.py ## 3. generate_ballot_issues.py
......
# init automation package # init automation package
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' """
This is the interface to MPEG GitLab API. This is the interface to MPEG GitLab API.
''' """
import os import os
import gitlab import gitlab
...@@ -10,98 +10,107 @@ from enum import Enum, unique ...@@ -10,98 +10,107 @@ from enum import Enum, unique
BASE_URL = 'http://mpegx.int-evry.fr/software' BASE_URL = 'http://mpegx.int-evry.fr/software'
TOKEN = os.environ.get('GITLAB_TOKEN') TOKEN = os.environ.get('GITLAB_TOKEN')
@unique @unique
class Label(Enum): class Label(Enum):
Accepted = 'Accepted' Accepted = 'Accepted'
BallotComment = 'BallotComment' BallotComment = 'BallotComment'
Combined = 'Combined' Combined = 'Combined'
DocAvailable = 'DocAvailable' DocAvailable = 'DocAvailable'
Editorial = 'Editorial' Editorial = 'Editorial'
Late = 'Late' Late = 'Late'
NeedsRevision = 'NeedsRevision' NeedsRevision = 'NeedsRevision'
Noted = 'Noted' Noted = 'Noted'
Postponed = 'Postponed' Postponed = 'Postponed'
ProbableAgreement = 'ProbableAgreement' ProbableAgreement = 'ProbableAgreement'
Rejected = 'Rejected' Rejected = 'Rejected'
Revised = 'Revised' Revised = 'Revised'
SeeDoCR = 'SeeDoCR' SeeDoCR = 'SeeDoCR'
Withdrawn = 'Withdrawn' Withdrawn = 'Withdrawn'
# private token authentication # private token authentication
GL = gitlab.Gitlab(BASE_URL, private_token=TOKEN) GL = gitlab.Gitlab(BASE_URL, private_token=TOKEN)
try: try:
GL.auth() GL.auth()
print('GitLab API: Authenticated as "{}"'.format(GL.user.username)) print('GitLab API: Authenticated as "{}"'.format(GL.user.username))
except gitlab.exceptions.GitlabAuthenticationError: except gitlab.exceptions.GitlabAuthenticationError:
print('Error: Could not authenticate. Please set the valid private GITLAB_TOKEN env. variable.') print('Error: Could not authenticate. Please set the valid private GITLAB_TOKEN env. variable.')
GL = None GL = None
def _get_project(project_id): def _get_project(project_id):
if not GL: if not GL:
print('Error: GitLab API authentication failed.') print('Error: GitLab API authentication failed.')
return return
try: try:
project = GL.projects.get(project_id) project = GL.projects.get(project_id)
except gitlab.exceptions.GitlabGetError as err: except gitlab.exceptions.GitlabGetError as err:
print('project_id', project_id, err) print('project_id', project_id, err)
return None return None
return project return project
# -------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------
# Interfaces # Interfaces
# -------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------
def get_projects(): def get_projects():
if not GL: if not GL:
print('Error: GitLab API authentication failed.') print('Error: GitLab API authentication failed.')
return [] return []
projects = GL.projects.list(all=True) projects = GL.projects.list(all=True)
projects_stripped = [] projects_stripped = []
for project in projects: for project in projects:
projects_stripped.append({ projects_stripped.append({
'id': project.id, 'id': project.id,
'name': project.name, 'name': project.name,
'url': project.web_url, 'url': project.web_url,
'path_with_namespace': project.path_with_namespace, 'path_with_namespace': project.path_with_namespace,
'description': project.description 'description': project.description
}) })
return projects_stripped return projects_stripped
def get_members(group_id): def get_members(group_id):
if not GL: if not GL:
print('Error: GitLab API authentication failed.') print('Error: GitLab API authentication failed.')
return [] return []
group = GL.groups.get(group_id) group = GL.groups.get(group_id)
subgroups = group.subgroups.list() subgroups = group.subgroups.list()
members_stripped = {} members_stripped = {}
for subgroup in subgroups: for subgroup in subgroups:
real_group = GL.groups.get(subgroup.id, lazy=True) real_group = GL.groups.get(subgroup.id, lazy=True)
members = real_group.members.all(all=True) members = real_group.members.all(all=True)
for member in members: for member in members:
if not member.username in members_stripped: if member.username not in members_stripped:
members_stripped[member.username] = { members_stripped[member.username] = {
'id': member.id, 'id': member.id,
'name': member.name, 'name': member.name,
'url': member.web_url 'url': member.web_url
} }
return members_stripped return members_stripped
def get_issues(project_id): def get_issues(project_id):
project = _get_project(project_id) project = _get_project(project_id)
if not project: if not project:
return [] return []
issues = project.issues.list(state='opened', all=True) issues = project.issues.list(state='opened', all=True)
return issues return issues
def open_issue(project_id, title, description, labels=[]):
project = _get_project(project_id)
if not project:
return
issue = project.issues.create({'title': title, 'description': description, 'labels': labels})
issue.save()
def close_issue(issue):
if isinstance(issue, gitlab.v4.objects.ProjectIssue): def open_issue(project_id, title, description, labels=None):
issue.state_event = 'close' project = _get_project(project_id)
if not project:
return
if labels is None:
labels = []
issue = project.issues.create({'title': title, 'description': description, 'labels': labels})
issue.save() issue.save()
def close_issue(issue):
if isinstance(issue, gitlab.v4.objects.ProjectIssue):
issue.state_event = 'close'
issue.save()
This diff is collapsed.
This diff is collapsed.
''' """
Just a few examples on how to use gitlab module Just a few examples on how to use gitlab module
''' """
import sys import sys
sys.path.append('..') # hack which allows to import module from the parent directory
sys.path.append('..') # hack which allows to import module from the parent directory
from automation import gitlab from automation import gitlab
# get all projects # get all projects
projects = gitlab.get_projects() projects = gitlab.get_projects()
print('project count:', len(projects)) print('project count:', len(projects))
for project in projects: for project in projects:
print(project) print(project)
issues = gitlab.get_issues(projects[0]['id']) issues = gitlab.get_issues(projects[0]['id'])
print('project {} has {} issues.'.format(projects[0]['url'], len(issues))) print('project {} has {} issues.'.format(projects[0]['url'], len(issues)))
\ No newline at end of file
''' """
Just a few examples on how to use mdms module Just a few examples on how to use mdms module
''' """
import sys import sys
sys.path.append('..') # hack which allows to import module from the parent directory
sys.path.append('..') # hack which allows to import module from the parent directory
from automation import mdms from automation import mdms
# Get all meetings # Get all meetings
...@@ -11,7 +12,8 @@ print('Number of MPEG meetings:', len(meetings)) ...@@ -11,7 +12,8 @@ print('Number of MPEG meetings:', len(meetings))
# Get latest meeting, (this calles mdms.get_meetings() internally) # Get latest meeting, (this calles mdms.get_meetings() internally)
last_meeting = mdms.get_current_meeting() last_meeting = mdms.get_current_meeting()
print('\nLast MPEG#{} ({}) from {} to {}'.format(last_meeting['number'], last_meeting['name'], last_meeting['start_date'], last_meeting['end_date'])) print('\nLast MPEG#{} ({}) from {} to {}'.format(last_meeting['number'], last_meeting['name'],
last_meeting['start_date'], last_meeting['end_date']))
# Get all input documents of a certain meeting # Get all input documents of a certain meeting
input_docs = mdms.get_input_documents(last_meeting['id']) input_docs = mdms.get_input_documents(last_meeting['id'])
......
This diff is collapsed.
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