@@ -29,11 +29,13 @@ def __init__(self, host, token="", verify_ssl=True):
29
29
self .host = host
30
30
if self .host [:7 ] != 'http://' :
31
31
self .host = 'http://' + self .host
32
- self .projects_url = self .host + "/api/v3/projects"
33
- self .users_url = self .host + "/api/v3/users"
34
- self .keys_url = self .host + "/api/v3/user/keys"
35
- self .groups_url = self .host + "/api/v3/groups"
36
- self .search_url = self .host + "/api/v3/projects/search/"
32
+
33
+ self .api_url = self .host + "/api/v3"
34
+ self .projects_url = self .api_url + "/projects"
35
+ self .users_url = self .api_url + "/users"
36
+ self .keys_url = self .api_url + "/user/keys"
37
+ self .groups_url = self .api_url + "/groups"
38
+ self .search_url = self .api_url + "/projects/search/"
37
39
self .verify_ssl = verify_ssl
38
40
39
41
def login (self , user , password ):
@@ -379,6 +381,18 @@ def createproject(self, name, description="", default_branch="",
379
381
380
382
return False
381
383
384
+ def deleteproject (self , project_id ):
385
+ """
386
+ Delete a project
387
+ :param id_: project id
388
+ :return: always true
389
+ """
390
+ request = requests .delete (self .projects_url + "/" + str (project_id ),
391
+ headers = self .headers )
392
+ if request .status_code == 200 :
393
+ return True
394
+
395
+
382
396
def createprojectuser (self , id_ , name , description = "" , default_branch = "" ,
383
397
issues_enabled = 0 , wall_enabled = 0 ,
384
398
merge_requests_enabled = 0 , wiki_enabled = 0 ,
@@ -961,11 +975,12 @@ def creategroup(self, name, path):
961
975
request = requests .post (self .groups_url ,
962
976
data = {'name' : name , 'path' : path },
963
977
headers = self .headers , verify = self .verify_ssl )
978
+ print request .status_code
979
+ print request .content
964
980
if request .status_code == 201 :
965
981
return True
966
982
else :
967
-
968
- return False
983
+ return exceptions .HttpError (json .loads (request .content )['message' ])
969
984
970
985
def getgroups (self , id_ = None , page = 1 , per_page = 20 , sudo = "" ):
971
986
"""
@@ -1317,51 +1332,226 @@ def getfilearchive(self, project_id, filepath="", sha1=""):
1317
1332
def deletegroup (self , group_id ):
1318
1333
"""
1319
1334
groups section, new in 6.2
1335
+
1336
+ Deletes an group by ID
1337
+ :param id_: id of the group to delete
1338
+ :return: True if it deleted, False if it couldn't. False could happen
1339
+ for several reasons, but there isn't a
1340
+ good way of differentiating them
1320
1341
"""
1321
- pass
1342
+ request = requests .delete (self .groups_url + "/" + str (group_id ),
1343
+ headers = self .headers )
1344
+ if request .status_code == 200 :
1345
+ return True
1346
+ else :
1347
+ return False
1322
1348
1323
- def listgroupmembers (self , id ):
1349
+ def listgroupmembers (self , group_id ):
1324
1350
"""
1325
1351
list group members
1326
1352
new in 6.2
1353
+
1354
+ lists the members of a given group id
1355
+ :param group_id: the group id
1356
+ :return: the group's members
1327
1357
"""
1328
- pass
1358
+ request = requests .get (self .groups_url + "/" + str (group_id ) + "/members" ,
1359
+ headers = self .headers , verify = self .verify_ssl )
1360
+ if request .status_code == 200 :
1361
+ return json .loads (request .content .decode ("utf-8" ))
1362
+ else :
1363
+ return False
1329
1364
1330
- def addgroupmember (self , group_id , user_id , access_level ):
1365
+ def addgroupmember (self , group_id , user_id , access_level , sudo = "" ):
1331
1366
"""
1332
1367
add a user to a group
1333
1368
new in 6.2
1369
+
1370
+ # check the access level and put into a number
1371
+
1372
+ adds a project member to a project
1373
+ :param id_: project id
1374
+ :param user_id: user id
1375
+ :param access_level: access level, see gitlab help to know more
1376
+ :param sudo: do the request with another user
1377
+ :return: True if success
1334
1378
"""
1335
- pass
1379
+ if access_level .lower () == "master" :
1380
+ access_level = 40
1381
+ elif access_level .lower () == "developer" :
1382
+ access_level = 30
1383
+ elif access_level .lower () == "reporter" :
1384
+ access_level = 20
1385
+ else :
1386
+ access_level = 10
1387
+ data = {"id" : group_id , "user_id" : user_id , "access_level" : access_level }
1388
+ if sudo != "" :
1389
+ data ['sudo' ] = sudo
1390
+ request = requests .post (self .groups_url + "/" + str (group_id ) + "/members" ,
1391
+ headers = self .headers , data = data , verify = self .verify_ssl )
1392
+ if request .status_code == 201 :
1393
+ return True
1394
+ else :
1395
+ return False
1336
1396
1337
- def removegroupmember (self , group_id , user_id ):
1397
+ def deletegroupmember (self , group_id , user_id ):
1338
1398
"""
1339
- remove a user from a group
1340
- new in 6.2
1399
+ Delete a group member
1400
+ :param id_: project id
1401
+ :param user_id: user id
1402
+ :return: always true
1341
1403
"""
1342
- pass
1343
-
1404
+ request = requests .delete (self .groups_url + "/" + str (group_id )
1405
+ + "/members/" + str (user_id ),
1406
+ headers = self .headers )
1407
+ if request .status_code == 200 :
1408
+ return True # It always returns true
1344
1409
1345
- # There is now a wall where you can post notes. All this below is new in 6.2
1346
- # there is also notes in issues, merge_requests and snippets so we need to
1347
- # create methods for all of them
1348
1410
def getprojectwallnotes (self , project_id ):
1349
1411
"""
1350
1412
get the notes from the wall of a project
1351
- new in 6.2
1352
1413
"""
1353
- pass
1414
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/notes" ,
1415
+ headers = self .headers )
1416
+
1417
+ if request .status_code == 200 :
1418
+ return json .loads (request .content .decode ("utf-8" ))
1419
+ else :
1420
+ return False
1354
1421
1355
1422
def getprojectwallnote (self , project_id , note_id ):
1356
1423
"""
1357
1424
get one note from the wall of the project
1358
1425
"""
1359
- pass
1426
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/notes/" + str (note_id ),
1427
+ headers = self .headers )
1428
+
1429
+ if request .status_code == 200 :
1430
+ return json .loads (request .content .decode ("utf-8" ))
1431
+ else :
1432
+ return False
1360
1433
1361
1434
def createprojectwallnote (self , project_id , content ):
1362
1435
"""
1363
1436
create a new note
1364
1437
"""
1365
- pass
1438
+ data = {"body" : content }
1439
+ request = requests .post (self .projects_url + "/" + str (project_id ) + "/notes" ,
1440
+ headers = self .headers , data = data )
1366
1441
1442
+ if request .status_code == 201 :
1443
+ return True
1444
+ else :
1445
+ return False
1446
+
1447
+ def getissuewallnotes (self , project_id , issue_id ):
1448
+ """
1449
+ get the notes from the wall of a issue
1450
+ """
1451
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/issues/" + str (issue_id ) + "/notes" ,
1452
+ headers = self .headers )
1453
+
1454
+ if request .status_code == 200 :
1455
+ return json .loads (request .content .decode ("utf-8" ))
1456
+ else :
1457
+ return False
1458
+
1459
+ def getissuewallnote (self , project_id , issue_id , note_id ):
1460
+ """
1461
+ get one note from the wall of the issue
1462
+ """
1463
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/issues/" + str (issue_id ) + "/notes/" + str (note_id ),
1464
+ headers = self .headers )
1465
+
1466
+ if request .status_code == 200 :
1467
+ return json .loads (request .content .decode ("utf-8" ))
1468
+ else :
1469
+ return False
1470
+
1471
+ def createissuewallnote (self , project_id , issue_id , content ):
1472
+ """
1473
+ create a new note
1474
+ """
1475
+ data = {"body" : content }
1476
+ request = requests .post (self .projects_url + "/" + str (project_id ) + "/issues/" + str (issue_id ) + "/notes" ,
1477
+ headers = self .headers , data = data )
1478
+
1479
+ if request .status_code == 201 :
1480
+ return True
1481
+ else :
1482
+ return False
1483
+
1484
+ def getsnippetwallnotes (self , project_id , snippet_id ):
1485
+ """
1486
+ get the notes from the wall of a snippet
1487
+ """
1488
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/snippets/" + str (snippet_id ) + "/notes" ,
1489
+ headers = self .headers )
1490
+
1491
+ if request .status_code == 200 :
1492
+ return json .loads (request .content .decode ("utf-8" ))
1493
+ else :
1494
+ return False
1495
+
1496
+ def getsnippetwallnote (self , project_id , snippet_id , note_id ):
1497
+ """
1498
+ get one note from the wall of the snippet
1499
+ """
1500
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/snippets/" + str (snippet_id ) + "/notes/" + str (note_id ),
1501
+ headers = self .headers )
1502
+
1503
+ if request .status_code == 200 :
1504
+ return json .loads (request .content .decode ("utf-8" ))
1505
+ else :
1506
+ return False
1507
+
1508
+ def createsnippetewallnote (self , project_id , snippet_id , content ):
1509
+ """
1510
+ create a new note
1511
+ """
1512
+ data = {"body" : content }
1513
+ request = requests .post (self .projects_url + "/" + str (project_id ) + "/snippets/" + str (snippet_id ) + "/notes" ,
1514
+ headers = self .headers , data = data )
1515
+
1516
+ if request .status_code == 201 :
1517
+ return True
1518
+ else :
1519
+ return False
1520
+
1521
+ def getmergerequestwallnotes (self , project_id , merge_request_id ):
1522
+ """
1523
+ get the notes from the wall of a merge request
1524
+ """
1525
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/merge_requests/" + str (merge_request_id ) + "/notes" ,
1526
+ headers = self .headers )
1527
+
1528
+ if request .status_code == 200 :
1529
+ return json .loads (request .content .decode ("utf-8" ))
1530
+ else :
1531
+ return False
1532
+
1533
+ def getmergerequestwallnote (self , project_id , merge_request_id , note_id ):
1534
+ """
1535
+ get one note from the wall of the merge request
1536
+ """
1537
+ request = requests .get (self .projects_url + "/" + str (project_id ) + "/merge_requests/" + str (merge_request_id ) + "/notes/" + str (note_id ),
1538
+ headers = self .headers )
1539
+
1540
+ if request .status_code == 200 :
1541
+ return json .loads (request .content .decode ("utf-8" ))
1542
+ else :
1543
+ return False
1544
+
1545
+ def createmergerequestewallnote (self , project_id , merge_request_id , content ):
1546
+ """
1547
+ create a new note
1548
+ """
1549
+ data = {"body" : content }
1550
+ request = requests .post (self .projects_url + "/" + str (project_id ) + "/merge_requests/" + str (merge_request_id ) + "/notes" ,
1551
+ headers = self .headers , data = data )
1552
+
1553
+ if request .status_code == 201 :
1554
+ return True
1555
+ else :
1556
+ return False
1367
1557
0 commit comments