Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testREST
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Saeed Hadadan
testREST
Commits
b48050fa
Commit
b48050fa
authored
5 years ago
by
Harrison Cook
Browse files
Options
Downloads
Patches
Plain Diff
required-functions
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
script_git.py
+70
-0
70 additions, 0 deletions
script_git.py
with
70 additions
and
0 deletions
script_git.py
0 → 100644
+
70
−
0
View file @
b48050fa
#!/usr/bin/python3
import
requests
as
r
import
json
as
j
SECRET_KEY
=
'
SWZskgnDTNUzVsQ7EmKs
'
BASE_URL
=
'
https://gitlab.cs.umd.edu/
'
DEFAULT_HEADERS
=
{
'
user-agent
'
:
'
bulk-repo-create
'
,
'
Content-Type
'
:
'
application/json
'
,
'
Private-Token
'
:
SECRET_KEY
}
def
id_from_name
(
name
):
rq
=
r
.
get
(
BASE_URL
+
"
api/v4/users/
"
,
headers
=
DEFAULT_HEADERS
,
params
=
{
'
username
'
:
name
}
)
res
=
j
.
loads
(
rq
.
text
)
if
type
(
res
)
==
list
:
if
len
(
res
)
==
0
:
return
None
else
:
return
res
[
0
][
'
id
'
]
else
:
raise
TypeError
# Returns project id, or none if project cannot be created
def
create_project
(
proj_name
):
rq
=
r
.
post
(
BASE_URL
+
"
api/v4/projects/
"
,
headers
=
DEFAULT_HEADERS
,
data
=
j
.
dumps
(
{
'
name
'
:
proj_name
,
'
visibility
'
:
'
private
'
}
)
)
res
=
j
.
loads
(
rq
.
text
)
try
:
return
res
[
'
id
'
]
except
KeyError
:
return
None
# adds user with user_id to project with project_id with permission permission
# 30 for developer 40 for maintainer
# return true if successful false if not
def
add_to_project
(
project_id
,
user_id
,
permission
):
rq
=
r
.
post
(
BASE_URL
+
"
api/v4/projects/
"
+
str
(
project_id
)
+
"
/members
"
,
headers
=
DEFAULT_HEADERS
,
data
=
j
.
dumps
(
{
'
id
'
:
project_id
,
'
user_id
'
:
user_id
,
'
access_level
'
:
permission
#Developer
}
)
)
res
=
j
.
loads
(
rq
.
text
)
try
:
return
res
[
'
id
'
]
==
user_id
except
KeyError
:
return
False
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