Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dimitri Podborski
AutomationTools
Commits
72944f6f
Commit
72944f6f
authored
Apr 12, 2021
by
Dimitri Podborski
Browse files
pip 8
parent
7aaf00e2
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
automation/__init__.py
View file @
72944f6f
# init automation package
\ No newline at end of file
# init automation package
automation/gitlab.py
View file @
72944f6f
# -*- coding: utf-8 -*-
'''
"""
This is the interface to MPEG GitLab API.
'''
"""
import
os
import
gitlab
...
...
@@ -10,98 +10,107 @@ from enum import Enum, unique
BASE_URL
=
'http://mpegx.int-evry.fr/software'
TOKEN
=
os
.
environ
.
get
(
'GITLAB_TOKEN'
)
@
unique
class
Label
(
Enum
):
Accepted
=
'Accepted'
BallotComment
=
'BallotComment'
Combined
=
'Combined'
DocAvailable
=
'DocAvailable'
Editorial
=
'Editorial'
Late
=
'Late'
NeedsRevision
=
'NeedsRevision'
Noted
=
'Noted'
Postponed
=
'Postponed'
ProbableAgreement
=
'ProbableAgreement'
Rejected
=
'Rejected'
Revised
=
'Revised'
SeeDoCR
=
'SeeDoCR'
Withdrawn
=
'Withdrawn'
Accepted
=
'Accepted'
BallotComment
=
'BallotComment'
Combined
=
'Combined'
DocAvailable
=
'DocAvailable'
Editorial
=
'Editorial'
Late
=
'Late'
NeedsRevision
=
'NeedsRevision'
Noted
=
'Noted'
Postponed
=
'Postponed'
ProbableAgreement
=
'ProbableAgreement'
Rejected
=
'Rejected'
Revised
=
'Revised'
SeeDoCR
=
'SeeDoCR'
Withdrawn
=
'Withdrawn'
# private token authentication
GL
=
gitlab
.
Gitlab
(
BASE_URL
,
private_token
=
TOKEN
)
try
:
GL
.
auth
()
print
(
'GitLab API: Authenticated as "{}"'
.
format
(
GL
.
user
.
username
))
GL
.
auth
()
print
(
'GitLab API: Authenticated as "{}"'
.
format
(
GL
.
user
.
username
))
except
gitlab
.
exceptions
.
GitlabAuthenticationError
:
print
(
'Error: Could not authenticate. Please set the valid private GITLAB_TOKEN env. variable.'
)
GL
=
None
print
(
'Error: Could not authenticate. Please set the valid private GITLAB_TOKEN env. variable.'
)
GL
=
None
def
_get_project
(
project_id
):
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
try
:
project
=
GL
.
projects
.
get
(
project_id
)
except
gitlab
.
exceptions
.
GitlabGetError
as
err
:
print
(
'project_id'
,
project_id
,
err
)
return
None
return
project
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
try
:
project
=
GL
.
projects
.
get
(
project_id
)
except
gitlab
.
exceptions
.
GitlabGetError
as
err
:
print
(
'project_id'
,
project_id
,
err
)
return
None
return
project
# --------------------------------------------------------------------------------------------------
# Interfaces
# --------------------------------------------------------------------------------------------------
def
get_projects
():
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
[]
projects
=
GL
.
projects
.
list
(
all
=
True
)
projects_stripped
=
[]
for
project
in
projects
:
projects_stripped
.
append
({
'id'
:
project
.
id
,
'name'
:
project
.
name
,
'url'
:
project
.
web_url
,
'path_with_namespace'
:
project
.
path_with_namespace
,
'description'
:
project
.
description
})
return
projects_stripped
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
[]
projects
=
GL
.
projects
.
list
(
all
=
True
)
projects_stripped
=
[]
for
project
in
projects
:
projects_stripped
.
append
({
'id'
:
project
.
id
,
'name'
:
project
.
name
,
'url'
:
project
.
web_url
,
'path_with_namespace'
:
project
.
path_with_namespace
,
'description'
:
project
.
description
})
return
projects_stripped
def
get_members
(
group_id
):
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
[]
group
=
GL
.
groups
.
get
(
group_id
)
subgroups
=
group
.
subgroups
.
list
()
members_stripped
=
{}
for
subgroup
in
subgroups
:
real_group
=
GL
.
groups
.
get
(
subgroup
.
id
,
lazy
=
True
)
members
=
real_group
.
members
.
all
(
all
=
True
)
for
member
in
members
:
if
not
member
.
username
in
members_stripped
:
members_stripped
[
member
.
username
]
=
{
'id'
:
member
.
id
,
'name'
:
member
.
name
,
'url'
:
member
.
web_url
}
return
members_stripped
if
not
GL
:
print
(
'Error: GitLab API authentication failed.'
)
return
[]
group
=
GL
.
groups
.
get
(
group_id
)
subgroups
=
group
.
subgroups
.
list
()
members_stripped
=
{}
for
subgroup
in
subgroups
:
real_group
=
GL
.
groups
.
get
(
subgroup
.
id
,
lazy
=
True
)
members
=
real_group
.
members
.
all
(
all
=
True
)
for
member
in
members
:
if
member
.
username
not
in
members_stripped
:
members_stripped
[
member
.
username
]
=
{
'id'
:
member
.
id
,
'name'
:
member
.
name
,
'url'
:
member
.
web_url
}
return
members_stripped
def
get_issues
(
project_id
):
project
=
_get_project
(
project_id
)
if
not
project
:
return
[]
issues
=
project
.
issues
.
list
(
state
=
'opened'
,
all
=
True
)
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
()
project
=
_get_project
(
project_id
)
if
not
project
:
return
[]
issues
=
project
.
issues
.
list
(
state
=
'opened'
,
all
=
True
)
return
issues
def
close_issue
(
issue
):
if
isinstance
(
issue
,
gitlab
.
v4
.
objects
.
ProjectIssue
):
issue
.
state_event
=
'close'
def
open_issue
(
project_id
,
title
,
description
,
labels
=
None
):
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
()
def
close_issue
(
issue
):
if
isinstance
(
issue
,
gitlab
.
v4
.
objects
.
ProjectIssue
):
issue
.
state_event
=
'close'
issue
.
save
()
automation/helpers.py
View file @
72944f6f
This diff is collapsed.
Click to expand it.
automation/mdms.py
View file @
72944f6f
This diff is collapsed.
Click to expand it.
examples/example_gitlab.py
View file @
72944f6f
'''
"""
Just a few examples on how to use gitlab module
'''
"""
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
# get all projects
projects
=
gitlab
.
get_projects
()
print
(
'project count:'
,
len
(
projects
))
for
project
in
projects
:
print
(
project
)
print
(
project
)
issues
=
gitlab
.
get_issues
(
projects
[
0
][
'id'
])
print
(
'project {} has {} issues.'
.
format
(
projects
[
0
][
'url'
],
len
(
issues
)))
\ No newline at end of file
print
(
'project {} has {} issues.'
.
format
(
projects
[
0
][
'url'
],
len
(
issues
)))
examples/example_mdms.py
View file @
72944f6f
'''
"""
Just a few examples on how to use mdms module
'''
"""
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
# Get all meetings
...
...
@@ -11,7 +12,8 @@ print('Number of MPEG meetings:', len(meetings))
# Get latest meeting, (this calles mdms.get_meetings() internally)
last_meeting
=
mdms
.
get_current_meeting
()
print
(
'
\n
Last MPEG#{} ({}) from {} to {}'
.
format
(
last_meeting
[
'number'
],
last_meeting
[
'name'
],
last_meeting
[
'start_date'
],
last_meeting
[
'end_date'
]))
print
(
'
\n
Last 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
input_docs
=
mdms
.
get_input_documents
(
last_meeting
[
'id'
])
...
...
systems.py
View file @
72944f6f
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment