Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CSCE 361
scripts
Commits
da38c3cf
Commit
da38c3cf
authored
Sep 16, 2019
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Added CompositeUser for CanvasUser-GitlabUser bijection
parent
3bbe2b7c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
canvas_classes.py
+4
-1
4 additions, 1 deletion
canvas_classes.py
composite_user.py
+98
-0
98 additions, 0 deletions
composite_user.py
gitlab_classes.py
+19
-19
19 additions, 19 deletions
gitlab_classes.py
with
121 additions
and
20 deletions
canvas_classes.py
+
4
−
1
View file @
da38c3cf
...
@@ -15,6 +15,9 @@ class CanvasSession:
...
@@ -15,6 +15,9 @@ class CanvasSession:
class
CanvasUser
:
class
CanvasUser
:
def
__init__
(
self
,
user
):
def
__init__
(
self
,
user
):
super
().
__init__
()
super
().
__init__
()
if
isinstance
(
user
,
int
):
# by NUID
self
.
canvas_user
=
CanvasSession
.
get_session
().
get_user
(
user
,
'
sis_user_id
'
)
else
:
self
.
canvas_user
=
user
self
.
canvas_user
=
user
def
get_name
(
self
):
def
get_name
(
self
):
...
...
This diff is collapsed.
Click to expand it.
composite_user.py
0 → 100644
+
98
−
0
View file @
da38c3cf
from
canvas_classes
import
CanvasUser
from
gitlab_classes
import
GitlabUser
import
csv
NO_PARTNERING_LIST_MAXIMUM
=
10
class
CompositeUser
:
def
__init__
(
self
,
student_dictionary
,
graylist
,
blacklist
):
self
.
canvas_user
=
None
self
.
gitlab_user
=
None
self
.
sortable_name
=
student_dictionary
[
'
SortableName
'
]
self
.
readable_name
=
student_dictionary
[
'
ReadableName
'
]
self
.
NUID
=
student_dictionary
[
'
NUID
'
]
self
.
canvas_username
=
student_dictionary
[
'
CanvasUsername
'
]
self
.
gitlab_username
=
student_dictionary
[
'
GitlabUsername
'
]
self
.
canvas_email
=
student_dictionary
[
'
CanvasEmail
'
]
self
.
gitlab_email
=
student_dictionary
[
'
GitlabEmail
'
]
self
.
graylist
=
set
(
graylist
)
self
.
blacklist
=
set
(
blacklist
)
self
.
candidate_teammates
=
None
def
get_canvas_user
(
self
):
if
self
.
canvas_user
is
None
:
self
.
canvas_user
=
CanvasUser
(
self
.
NUID
)
return
self
.
canvas_user
def
get_gitlab_user
(
self
):
if
self
.
gitlab_user
is
None
:
self
.
gitlab_user
=
GitlabUser
(
self
.
NUID
)
return
self
.
gitlab_user
def
tentatively_pair_with
(
self
,
username
):
self
.
candidate_teammates
=
{
username
}
def
tentatively_team_with
(
self
,
usernames
):
self
.
candidate_teammates
=
set
(
usernames
)
def
commit_team
(
self
):
self
.
graylist
=
self
.
graylist
.
union
(
self
.
candidate_teammates
)
def
discard_team
(
self
):
self
.
candidate_teammates
=
None
@staticmethod
def
read_student_csv
(
filename
):
students
=
set
()
with
open
(
filename
,
mode
=
'
r
'
)
as
csv_file
:
csv_reader
=
csv
.
DictReader
(
csv_file
)
for
student
in
csv_reader
:
graylist
=
set
()
blacklist
=
set
()
for
count
in
range
(
NO_PARTNERING_LIST_MAXIMUM
):
former_partner
=
student
[
f
'
Graylist
{
count
}
'
]
undesired_partner
=
student
[
f
'
Blacklist
{
count
}
'
]
if
former_partner
!=
""
:
graylist
.
add
(
former_partner
)
if
undesired_partner
!=
""
:
blacklist
.
add
(
undesired_partner
)
student
=
CompositeUser
(
student
,
graylist
,
blacklist
)
students
.
add
(
student
)
return
students
@staticmethod
def
write_student_csv
(
students
,
filename
):
with
open
(
filename
,
mode
=
'
w
'
)
as
csv_file
:
fieldnames
=
[
'
SortableName
'
,
'
ReadableName
'
,
'
NUID
'
,
'
CanvasUsername
'
,
'
CanvasEmail
'
,
'
GitlabUsername
'
,
'
GitlabEmail
'
]
for
count
in
range
(
NO_PARTNERING_LIST_MAXIMUM
):
fieldnames
.
append
(
f
'
Graylist
{
count
}
'
)
for
count
in
range
(
NO_PARTNERING_LIST_MAXIMUM
):
fieldnames
.
append
(
f
'
Blacklist
{
count
}
'
)
writer
=
csv
.
DictWriter
(
csv_file
,
fieldnames
=
fieldnames
)
writer
.
writeheader
()
for
student
in
students
:
student_dictionary
=
{
'
SortableName
'
:
student
.
sortable_name
.
strip
(),
'
ReadableName
'
:
student
.
readable_name
.
strip
(),
'
NUID
'
:
student
.
NUID
,
'
CanvasUsername
'
:
student
.
canvas_username
,
'
CanvasEmail
'
:
student
.
canvas_email
,
'
GitlabUsername
'
:
student
.
gitlab_username
,
'
GitlabEmail
'
:
student
.
gitlab_email
}
count
=
0
for
former_partner
in
student
.
graylist
:
student_dictionary
.
update
({
f
'
Graylist
{
count
}
'
:
former_partner
})
count
+=
1
while
count
<
NO_PARTNERING_LIST_MAXIMUM
:
student_dictionary
.
update
({
f
'
Graylist
{
count
}
'
:
''
})
count
+=
1
count
=
0
for
undesired_partner
in
student
.
blacklist
:
student_dictionary
.
update
({
f
'
Blacklist
{
count
}
'
:
undesired_partner
})
count
+=
1
while
count
<
NO_PARTNERING_LIST_MAXIMUM
:
student_dictionary
.
update
({
f
'
Blacklist
{
count
}
'
:
''
})
count
+=
1
writer
.
writerow
(
student_dictionary
)
This diff is collapsed.
Click to expand it.
gitlab_classes.py
+
19
−
19
View file @
da38c3cf
...
@@ -4,17 +4,17 @@ import gitlab
...
@@ -4,17 +4,17 @@ import gitlab
from
config
import
Config
from
config
import
Config
class
Session
:
class
Gitlab
Session
:
__instance
=
None
__instance
=
None
@staticmethod
@staticmethod
def
get_session
():
def
get_session
():
if
Session
.
__instance
is
None
:
if
Gitlab
Session
.
__instance
is
None
:
Session
.
__instance
=
gitlab
.
Gitlab
(
Config
.
gitlab_url
,
private_token
=
Config
.
gitlab_api_key
)
Gitlab
Session
.
__instance
=
gitlab
.
Gitlab
(
Config
.
gitlab_url
,
private_token
=
Config
.
gitlab_api_key
)
return
Session
.
__instance
return
Gitlab
Session
.
__instance
class
User
:
class
Gitlab
User
:
def
__init__
(
self
,
user
):
def
__init__
(
self
,
user
):
"""
"""
Creates a User object, populating the backing git_user instance with the appropriate gitlab.User object
Creates a User object, populating the backing git_user instance with the appropriate gitlab.User object
...
@@ -23,9 +23,9 @@ class User:
...
@@ -23,9 +23,9 @@ class User:
"""
"""
super
().
__init__
()
super
().
__init__
()
if
isinstance
(
user
,
int
):
# by user id
if
isinstance
(
user
,
int
):
# by user id
self
.
git_user
=
Session
.
get_session
().
users
.
get
(
user
)
self
.
git_user
=
Gitlab
Session
.
get_session
().
users
.
get
(
user
)
elif
isinstance
(
user
,
str
):
# by username
elif
isinstance
(
user
,
str
):
# by username
self
.
git_user
=
Session
.
get_session
().
users
.
list
(
username
=
user
)[
0
]
self
.
git_user
=
Gitlab
Session
.
get_session
().
users
.
list
(
username
=
user
)[
0
]
else
:
else
:
self
.
git_user
=
user
self
.
git_user
=
user
...
@@ -168,12 +168,12 @@ class Project:
...
@@ -168,12 +168,12 @@ class Project:
"""
"""
super
().
__init__
()
super
().
__init__
()
if
isinstance
(
project
,
int
):
# by project id
if
isinstance
(
project
,
int
):
# by project id
self
.
git_project
=
Session
.
get_session
().
projects
.
get
(
project
)
self
.
git_project
=
Gitlab
Session
.
get_session
().
projects
.
get
(
project
)
elif
isinstance
(
project
,
str
):
# by path
elif
isinstance
(
project
,
str
):
# by path
self
.
git_project
=
Session
.
get_session
().
projects
.
get
(
project
)
self
.
git_project
=
Gitlab
Session
.
get_session
().
projects
.
get
(
project
)
else
:
else
:
# self.git_project = project # for some reason, many attributes (including members) might be lost
# self.git_project = project # for some reason, many attributes (including members) might be lost
self
.
git_project
=
Session
.
get_session
().
projects
.
get
(
project
.
id
)
self
.
git_project
=
Gitlab
Session
.
get_session
().
projects
.
get
(
project
.
id
)
@staticmethod
@staticmethod
def
get_projects_by_group
(
group
):
def
get_projects_by_group
(
group
):
...
@@ -182,9 +182,9 @@ class Project:
...
@@ -182,9 +182,9 @@ class Project:
:return: list of projects in the specified group
:return: list of projects in the specified group
"""
"""
if
isinstance
(
group
,
int
):
# by group id
if
isinstance
(
group
,
int
):
# by group id
gitlab_projects
=
Session
.
get_session
().
groups
.
get
(
group
).
projects
.
list
(
all
=
True
)
gitlab_projects
=
Gitlab
Session
.
get_session
().
groups
.
get
(
group
).
projects
.
list
(
all
=
True
)
else
:
# isinstance(group, str): # by path
else
:
# isinstance(group, str): # by path
gitlab_projects
=
Session
.
get_session
().
groups
.
get
(
group
).
projects
.
list
(
all
=
True
)
gitlab_projects
=
Gitlab
Session
.
get_session
().
groups
.
get
(
group
).
projects
.
list
(
all
=
True
)
projects
=
[]
projects
=
[]
for
project
in
gitlab_projects
:
for
project
in
gitlab_projects
:
projects
.
append
(
Project
(
project
))
projects
.
append
(
Project
(
project
))
...
@@ -192,7 +192,7 @@ class Project:
...
@@ -192,7 +192,7 @@ class Project:
@staticmethod
@staticmethod
def
get_projects_by_keyword
(
search_term
):
def
get_projects_by_keyword
(
search_term
):
gitlab_projects
=
Session
.
get_session
().
projects
.
list
(
search
=
search_term
,
all
=
True
)
gitlab_projects
=
Gitlab
Session
.
get_session
().
projects
.
list
(
search
=
search_term
,
all
=
True
)
projects
=
[]
projects
=
[]
for
project
in
gitlab_projects
:
for
project
in
gitlab_projects
:
projects
.
append
(
Project
(
project
))
projects
.
append
(
Project
(
project
))
...
@@ -200,12 +200,12 @@ class Project:
...
@@ -200,12 +200,12 @@ class Project:
@staticmethod
@staticmethod
def
create_project
(
project_name
):
def
create_project
(
project_name
):
return
Session
.
get_session
().
projects
.
create
({
'
name
'
:
project_name
})
return
Gitlab
Session
.
get_session
().
projects
.
create
({
'
name
'
:
project_name
})
@staticmethod
@staticmethod
def
create_project_in_group
(
group_name
,
project_name
):
def
create_project_in_group
(
group_name
,
project_name
):
group_id
=
Session
.
get_session
().
groups
.
get
(
group_name
).
id
group_id
=
Gitlab
Session
.
get_session
().
groups
.
get
(
group_name
).
id
return
Session
.
get_session
().
projects
.
create
({
'
name
'
:
project_name
,
'
namespace_id
'
:
group_id
})
return
Gitlab
Session
.
get_session
().
projects
.
create
({
'
name
'
:
project_name
,
'
namespace_id
'
:
group_id
})
def
get_project_id
(
self
):
def
get_project_id
(
self
):
return
self
.
git_project
.
id
return
self
.
git_project
.
id
...
@@ -262,7 +262,7 @@ class Project:
...
@@ -262,7 +262,7 @@ class Project:
"""
"""
:return: User object backed by the gitlab.User object representing the user who created the repo
:return: User object backed by the gitlab.User object representing the user who created the repo
"""
"""
return
User
(
self
.
git_project
.
creator_id
)
return
Gitlab
User
(
self
.
git_project
.
creator_id
)
def
get_created_at
(
self
):
def
get_created_at
(
self
):
"""
"""
...
@@ -280,7 +280,7 @@ class Project:
...
@@ -280,7 +280,7 @@ class Project:
gitlab_users
=
self
.
git_project
.
members
.
list
(
all
=
True
)
gitlab_users
=
self
.
git_project
.
members
.
list
(
all
=
True
)
users
=
[]
users
=
[]
for
user
in
gitlab_users
:
for
user
in
gitlab_users
:
users
.
append
(
User
(
user
))
users
.
append
(
Gitlab
User
(
user
))
return
users
return
users
def
get_all_users
(
self
):
def
get_all_users
(
self
):
...
@@ -290,7 +290,7 @@ class Project:
...
@@ -290,7 +290,7 @@ class Project:
gitlab_users
=
self
.
git_project
.
members
.
all
(
all
=
True
)
gitlab_users
=
self
.
git_project
.
members
.
all
(
all
=
True
)
users
=
[]
users
=
[]
for
user
in
gitlab_users
:
for
user
in
gitlab_users
:
users
.
append
(
User
(
user
))
users
.
append
(
Gitlab
User
(
user
))
return
users
return
users
def
add_user_as_maintainer
(
self
,
user
):
def
add_user_as_maintainer
(
self
,
user
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment