Skip to content

bitbucket

Bitbucket

Bases: BitbucketBase

Source code in server/vendor/atlassian/bitbucket/__init__.py
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
class Bitbucket(BitbucketBase):
    def __init__(self, url, *args, **kwargs):
        if "cloud" not in kwargs and ("bitbucket.org" in url):
            kwargs["cloud"] = True
        if "api_version" not in kwargs:
            kwargs["api_version"] = "2.0" if "cloud" in kwargs and kwargs["cloud"] else "1.0"
        if "cloud" in kwargs:
            kwargs["api_root"] = "" if "api.bitbucket.org" in url else "rest/api"

        super(Bitbucket, self).__init__(url, *args, **kwargs)

    def markup_preview(self, data):
        """
        Preview generated HTML for the given markdown content.
        Only authenticated users may call this resource.
        :param data:
        :return:
        """

        url = self.resource_url("markup/preview")
        return self.post(url, data=data)

    ################################################################################################
    # Administrative functions
    ################################################################################################

    def _url_admin(self, api_version=None):
        return self.resource_url("admin", api_version=api_version)

    def get_groups(self, group_filter=None, limit=25, start=0):
        """
        Get list of bitbucket groups.
        Use 'group_filter' for get specific group or get all group if necessary.

        :param group_filter: str - groupname
        :param limit: int - paginated limit to retrieve
        :param start: int - paginated point to start retrieving
        :return: The collection as JSON with all relevant information about the group
        """
        url = self.resource_url("groups", api_version="1.0")
        params = {}
        if group_filter:
            params["filter"] = group_filter
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start
        return self._get_paged(url, params=params)

    def group_members(self, group, start=0, limit=None):
        """
        Get group of members
        :param group: The group name to query
        :param start:
        :param limit:
        :return: A list of group members
        """

        url = "{}/groups/more-members".format(self._url_admin())
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if group:
            params["context"] = group
        return self._get_paged(url, params=params)

    def all_project_administrators(self):
        """
        Get the list of project administrators

        :return: A generator object containing a map with the project_key, project_name and project_administrators
        """
        for project in self.project_list():
            log.info("Processing project: %s - %s", project.get("key"), project.get("name"))
            yield {
                "project_key": project.get("key"),
                "project_name": project.get("name"),
                "project_administrators": [
                    {"email": x["emailAddress"], "name": x["displayName"]}
                    for x in self.project_users_with_administrator_permissions(project["key"])
                ],
            }

    def reindex(self):
        """
        Rebuild the bundled Elasticsearch indexes for Bitbucket Server
        :return:
        """
        url = self.resource_url("sync", api_root="rest/indexing", api_version="latest")
        return self.post(url)

    def check_reindexing_status(self):
        """
        Check reindexing status
        :return:
        """
        url = self.resource_url("status", api_root="rest/indexing", api_version="latest")
        return self.get(url)

    def get_users(self, user_filter=None, limit=25, start=0):
        """
        Get list of bitbucket users.
        Use 'user_filter' for get specific users or get all users if necessary.
        :param user_filter: str - username, displayname or email
        :param limit: int - paginated limit to retrieve
        :param start: int - paginated point to start retreiving
        :return: The collection as JSON with all relevant information about the licensed user
        """
        url = self.resource_url("users", api_version="1.0")
        params = {}
        if user_filter:
            params["filter"] = user_filter
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start
        return self.get(url, params=params)

    def get_users_info(self, user_filter=None, start=0, limit=25):
        """
        The authenticated user must have the LICENSED_USER permission to call this resource.
        :param user_filter: if specified only users with usernames, display name or email addresses
            containing the supplied string will be returned
        :param limit:
        :param start:
        :return:
        """
        url = "{}/users".format(self._url_admin(api_version="1.0"))
        params = {}
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start
        if user_filter:
            params["filter"] = user_filter
        return self._get_paged(url, params=params)

    def get_current_license(self):
        """
        Retrieves details about the current license, as well as the current status of the system with
        regard to the installed license. The status includes the current number of users applied
        toward the license limit, as well as any status messages about the license (warnings about expiry
        or user counts exceeding license limits).
        The authenticated user must have ADMIN permission. Unauthenticated users, and non-administrators,
        are not permitted to access license details.
        :return:
        """
        url = "{}/license".format(self._url_admin())
        return self.get(url)

    def _url_mail_server(self):
        return "{}/mail-server".format(self._url_admin())

    def get_mail_configuration(self):
        """
        Retrieves the current mail configuration.
        The authenticated user must have the SYS_ADMIN permission to call this resource.
        :return:
        """
        url = self._url_mail_server()
        return self.get(url)

    def _url_mail_server_sender_address(self):
        return "{}/sender-address".format(self._url_mail_server())

    def get_mail_sender_address(self):
        """
        Retrieves the server email address
        :return:
        """
        url = self._url_mail_server_sender_address()
        return self.get(url)

    def remove_mail_sender_address(self):
        """
        Clears the server email address.
        The authenticated user must have the ADMIN permission to call this resource.
        :return:
        """
        url = self._url_mail_server_sender_address()
        return self.delete(url)

    def get_ssh_settings(self):
        """
        Retrieve ssh settings for user
        :return:
        """
        url = self.resource_url("settings", api_root="rest/ssh")
        return self.get(url)

    def health_check(self):
        """
        Get health status
        https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html
        :return:
        """
        # check as Troubleshooting & Support Tools Plugin
        response = self.get("rest/troubleshooting/1.0/check/")
        if not response:
            # check as support tools
            response = self.get("rest/supportHealthCheck/1.0/check/")
        return response

    def get_associated_build_statuses(self, commit):
        """
        To get the build statuses associated with a commit.
        :commit: str- commit id
        :return:
        """
        url = self.resource_url(
            "commits/{commitId}".format(commitId=commit),
            api_root="rest/build-status",
        )
        return self.get(url)

    def _url_announcement_banner(self):
        return "{}/banner".format(self._url_admin())

    def get_announcement_banner(self):
        """
        Gets the announcement banner, if one exists and is available to the user
        :return:
        """
        url = self._url_announcement_banner()
        return self.get(url)

    def set_announcement_banner(self, body):
        """
        Sets the announcement banner with the provided JSON.
        Only users authenticated as Admins may call this resource
        :param body
            {
                "id": "https://docs.atlassian.com/jira/REST/schema/rest-announcement-banner#",
                "title": "Rest Announcement Banner",
                "type": "object"
            }
        :return:
        """
        url = self._url_announcement_banner()
        return self.put(url, data=body)

    def delete_announcement_banner(self):
        """
        Gets the announcement banner, if one exists and is available to the user
        :return:
        """
        url = self._url_announcement_banner()
        return self.delete(url)

    def upload_plugin(self, plugin_path):
        """
        Provide plugin path for upload into BitBucket e.g. useful for auto deploy
        :param plugin_path:
        :return:
        """
        upm_token = self.request(
            method="GET",
            path="rest/plugins/1.0/",
            headers=self.no_check_headers,
            trailing=True,
        ).headers["upm-token"]
        url = "rest/plugins/1.0/?token={}".format(upm_token)
        files = {"plugin": open(plugin_path, "rb")}
        return self.post(url, files=files, headers=self.no_check_headers)

    def get_categories(self, project_key, repository_slug=None):
        """
        Get a list of categories assigned to a project or repository.
        :param project_key: The project key as shown in URL.
        :param repository_slug: The repository as shown in URL (optional).
        :return: If 'repository_slug', returns the list with categories of the repository,
        otherwise, returns the list with the categories of the project 'project_key'
        """
        url = "project/{}".format(project_key)
        if repository_slug:
            url = "{}/repository/{}".format(url, repository_slug)
        url = self.resource_url(url, api_root="rest/categories", api_version="latest")
        data = self.get(url)
        return data.get("result").get("categories")

    ################################################################################################
    # Functions related to projects
    ################################################################################################

    def _url_projects(self, api_root=None, api_version=None):
        return self.resource_url("projects", api_root, api_version)

    def project_list(self, start=0, limit=None):
        """
        Provide the project list

        :return: A list of projects
        """
        url = self._url_projects()
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def create_project(self, key, name, description=""):
        """
        Create project
        :param key: The project key
        :param name: The project name
        :param description: The project description

        :return: The value of the post request.
        """
        url = self._url_projects()
        data = {"key": key, "name": name, "description": description}
        return self.post(url, data=data)

    ################################################################################################
    # Functions related to a specific project
    ################################################################################################

    def _url_project(self, project_key, api_root=None, api_version=None):
        return "{}/{}".format(self._url_projects(api_root, api_version), project_key)

    def project(self, key):
        """
        Provide project info
        :param key: The project key
        :return:
        """
        url = self._url_project(key)
        return self.get(url) or {}

    def project_exists(self, project_key):
        """
        Check if project with the provided project key exists and available.
        :param project_key: Key of the project where to check for repository.
        :return: False is requested repository doesn't exist in the project or not accessible to the requestor
        """
        exists = False
        try:
            self.project(project_key)
            exists = True
        except HTTPError as e:
            if e.response.status_code in (401, 404):
                pass
        return exists

    def update_project(self, key, **params):
        """
        Update project
        :param key: The project key
        :return: The value of the put request.
        """
        url = self._url_project(key)
        return self.put(url, data=params)

    def _url_project_avatar(self, project_key):
        return "{}/avatar.png".format(self._url_project(project_key))

    def project_summary(self, key):
        """
        Get a project summary
        :param key: The project key

        :return: Map with the project information
        """
        return {
            "key": key,
            "data": self.project(key),
            "users": self.project_users(key),
            "groups": self.project_groups(key),
            "avatar": self.project_avatar(key),
        }

    def project_avatar(self, key, content_type="image/png"):
        """
        Get project avatar
        :param key: The project key
        :param content_type: The content type to get

        :return: Value of get request
        """
        url = self._url_project_avatar(key)
        headers = dict(self.default_headers)
        headers["Accept"] = content_type
        headers["X-Atlassian-Token"] = "no-check"

        return self.get(url, not_json_response=True, headers=headers)

    def set_project_avatar(self, key, icon, content_type="image/png"):
        """
        Set project avatar
        :param key: The Project key
        :param icon: The icon file
        :param content_type: The content type of icon

        :return: Value of post request
        """
        url = self._url_project_avatar(key)
        headers = {"X-Atlassian-Token": "no-check"}
        files = {"avatar": ("avatar.png", icon, content_type)}
        return self.post(url, files=files, headers=headers)

    def project_keys(self, key, start=0, limit=None, filter_str=None):
        """
        Get SSH access keys added to the project
        :param start:
        :param limit:
        :param key: The project key
        :param filter_str:  OPTIONAL: users filter string
        :return: The list of SSH access keys
        """
        url = "{}/ssh".format(self._url_project(key, api_root="rest/keys"))
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def _url_project_users(self, project_key):
        return "{}/permissions/users".format(self._url_project(project_key))

    def project_users(self, key, start=0, limit=None, filter_str=None):
        """
        Get users with permission in project
        :param key: The project key
        :param filter_str:  OPTIONAL: users filter string
        :param start:
        :param limit:
        :return: The list of project users
        """
        url = self._url_project_users(key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def project_users_with_administrator_permissions(self, key):
        """
        Get project administrators for project
        :param key: The project key
        :return: List of project administrators
        """
        project_administrators = [
            user["user"] for user in self.project_users(key) if user["permission"] == "PROJECT_ADMIN"
        ]
        for group in self.project_groups_with_administrator_permissions(key):
            for user in self.group_members(group):
                project_administrators.append(user)
        return project_administrators

    def project_grant_user_permissions(self, project_key, username, permission):
        """
        Grant the specified project permission to a specific user
        :param project_key: The project key
        :param username: username to be granted
        :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
        :return:
        """
        url = self._url_project_users(project_key)
        params = {"permission": permission, "name": username}
        return self.put(url, params=params)

    def project_remove_user_permissions(self, project_key, username):
        """
        Revoke all permissions for the specified project for a user.
        The authenticated user must have PROJECT_ADMIN permission for
        the specified project or a higher global permission to call this resource.
        In addition, a user may not revoke their own project permissions if they do not have a higher global permission.
        :param project_key: The project key
        :param username: username to be granted
        :return:
        """
        url = self._url_project_users(project_key)
        params = {"name": username}
        return self.delete(url, params=params)

    def _url_project_groups(self, project_key):
        return "{}/permissions/groups".format(self._url_project(project_key))

    def project_groups(self, key, start=0, limit=None, filter_str=None):
        """
        Get Project Groups
        :param limit:
        :param limit:
        :param start:
        :param key: The project key
        :param filter_str: OPTIONAL: group filter string
        :return:
        """
        url = self._url_project_groups(key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def project_grant_group_permissions(self, project_key, group_name, permission):
        """
        Grant the specified project permission to a specific group
        :param project_key: The project key
        :param group_name: group to be granted
        :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
        :return:
        """
        url = self._url_project_groups(project_key)
        params = {"permission": permission, "name": group_name}
        return self.put(url, params=params)

    def project_remove_group_permissions(self, project_key, groupname):
        """
        Revoke all permissions for the specified project for a group.
        The authenticated user must have PROJECT_ADMIN permission for the specified project
        or a higher global permission to call this resource.
        In addition, a user may not revoke a group's permissions
        if it will reduce their own permission level.
        :param project_key: The project key
        :param groupname: group to be granted
        :return:
        """
        url = self._url_project_groups(project_key)
        params = {"name": groupname}
        return self.delete(url, params=params)

    def project_default_permissions(self, project_key, permission):
        """
        Check if the specified permission is the default permission for a given project
        :param project_key: The project key
        :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
        :return:
        """
        url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
        return self.get(url)

    def project_grant_default_permissions(self, project_key, permission):
        """
        Grant the specified project permission to all users for a given project
        :param project_key: The project key
        :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
        :return:
        """
        url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
        return self.post(url, params={"allow": True})

    def project_remove_default_permissions(self, project_key, permission):
        """
        Revoke the specified project permission for all users for a given project
        :param project_key: The project key
        :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
        :return:
        """
        url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
        return self.post(url, params={"allow": False})

    def _url_project_repo_hook_settings(self, project_key):
        return "{}/settings/hooks".format(self._url_project(project_key))

    def all_project_repo_hook_settings(self, project_key, start=0, limit=None, filter_type=None):
        """
        Get all repository hooks for a given project
        :param project_key: The project key
        :param start:
        :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
                fixed system limits. Default by built-in method: None
        :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present,
                                    controls how repository hooks should be filtered.
        :return:
        """
        url = self._url_project_repo_hook_settings(project_key)
        params = {}
        if filter_type:
            params["type"] = filter_type
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def get_project_repo_hook_settings(self, project_key, hook_key):
        """
        Get a repository hook from a given project
        :param project_key: The project key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}".format(self._url_project_repo_hook_settings(project_key), hook_key)
        return self.get(url)

    def enable_project_repo_hook_settings(self, project_key, hook_key):
        """
        Enable a repository hook for a given project
        :param project_key: The project key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}/enabled".format(self._url_project_repo_hook_settings(project_key), hook_key)
        return self.put(url)

    def disable_project_repo_hook_settings(self, project_key, hook_key):
        """
        Disable a repository hook for a given project
        :param project_key: The project key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}/enabled".format(self._url_project_repo_hook_settings(project_key), hook_key)
        return self.delete(url)

    def _url_project_conditions(self, project_key):
        return "{}/conditions".format(
            self._url_project(
                project_key,
                api_root="rest/default-reviewers",
                api_version="1.0",
            )
        )

    def get_project_conditions(self, project_key):
        """
        Request type: GET
        Return a page of defaults conditions with reviewers list that have been configured for this project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264904368
        :projectKey: str
        :return:
        """
        url = self._url_project_conditions(project_key)
        return self.get(url) or {}

    def _url_project_condition(self, project_key, id_condition=None):
        url = "{}/condition".format(
            self._url_project(
                project_key,
                api_root="rest/default-reviewers",
                api_version="1.0",
            )
        )
        if id_condition is not None:
            url += "/{}".format(id_condition)
        return url

    def get_project_condition(self, project_key, id_condition):
        """
        Request type: GET
        Return a specific condition with reviewers list that has been configured for this project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264901504
        :projectKey: str - project key involved
        :idCondition: int - condition id involved
        :return:
        """
        url = self._url_project_condition(project_key, id_condition)
        return self.get(url) or {}

    def create_project_condition(self, project_key, condition):
        """
        Request type: POST
        Create a new condition for this project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264893584
        :projectKey: str- project key involved
        :data: condition: dictionary object
        :example condition: '{"sourceMatcher":
                                {"id":"any",
                                "type":{"id":"ANY_REF"}},
                                "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                                "reviewers":[{"id": 12}],"requiredApprovals":"0"
                            }'
        :return:
        """
        url = self._url_project_condition(project_key)
        return self.post(url, data=condition) or {}

    def update_project_condition(self, project_key, condition, id_condition):
        """
        Request type: PUT
        Update a new condition for this project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
        :projectKey: str- project key involved
        :idCondition: int - condition id involved
        :data: condition: dictionary object
        :example condition: '{"sourceMatcher":
                                {"id":"any",
                                "type":{"id":"ANY_REF"}},
                                "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                                "reviewers":[{"id": 12}],"requiredApprovals":"0"
                            }'
        :return:
        """
        url = self._url_project_condition(project_key, id_condition)
        return self.put(url, data=condition) or {}

    def delete_project_condition(self, project_key, id_condition):
        """
        Delete a specific condition for this repository slug inside project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264896304
        Request type: DELETE
        :projectKey: str- project key involved
        :idCondition: int - condition id involved
        :return:
        """
        url = self._url_project_condition(project_key, id_condition)
        return self.delete(url) or {}

    def _url_project_audit_log(self, project_key):
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")

        return "{}/events".format(self._url_project(project_key, api_root="rest/audit"))

    def get_project_audit_log(self, project_key, start=0, limit=None):
        """
        Get the audit log of the project
        :param start:
        :param limit:
        :param project_key: The project key
        :return: List of events of the audit log
        """
        url = self._url_project_audit_log(project_key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def _url_repos(self, project_key, api_root=None, api_version=None):
        return "{}/repos".format(self._url_project(project_key, api_root, api_version))

    def repo_list(self, project_key, start=0, limit=25):
        """
        Get repositories list from project

        :param project_key: The project key
        :param start:
        :param limit:
        :return:
        """
        url = self._url_repos(project_key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def repo_all_list(self, project_key):
        """
        Get all repositories list from project
        :param project_key:
        :return:
        """
        return self.repo_list(project_key, limit=None)

    def create_repo(self, project_key, repository_slug, forkable=False, is_private=True):
        """Create a new repository.

        Requires an existing project in which this repository will be created. The only parameters which will be used
        are name and scmId.

        The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource.

        :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
        :type project_key: str
        :param repository_slug: Name of repository to create (i.e. "My repo").
        :param forkable: Set the repository to be forkable or not.
        :type forkable: bool
        :param is_private: Set the repository to be private or not.
        :type is_private: bool
        :return:
            201 - application/json (repository)
            400 - application/json (errors)
            401 - application/json (errors)
            409 - application/json (errors)
        :rtype: requests.Response
        """
        url = self._url_repos(project_key)
        data = {
            "name": repository_slug,
            "scmId": "git",
            "forkable": forkable,
            "is_private": is_private,
        }
        return self.post(url, data=data)

    ################################################################################################
    # Functions related to a specific repository
    ################################################################################################

    def _url_repo(self, project_key, repo, api_root=None, api_version=None):
        return "{}/{}".format(self._url_repos(project_key, api_root, api_version), repo)

    def reindex_repo(self, project_key, repository_slug):
        """
        Reindex repo
        :param project_key:
        :param repository_slug:
        :return:
        """
        url = "{urlRepo}/sync".format(
            urlRepo=self._url_repo(
                project_key,
                repository_slug,
                api_root="rest/indexing",
                api_version="1.0",
            )
        )
        return self.post(url)

    def reindex_repo_dev_panel(self, project_key, repository_slug):
        """
        Reindex all the Jira issues related to this repository_slug, including branches and pull requests.
        This automatically happens as part of an upgrade, and calling this manually should only be required
        if something unforeseen happens and the index becomes out of sync.
        The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
        :param project_key:
        :param repository_slug:
        :return:
        """
        url = "{}/reindex".format(self._url_repo(project_key, repository_slug, api_root="rest/jira-dev"))
        return self.post(url)

    def get_repo(self, project_key, repository_slug):
        """
        Get a specific repository from a project. This operates based on slug not name which may
        be confusing to some users.
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :return: Dictionary of request response
        """
        url = self._url_repo(project_key, repository_slug)
        return self.get(url)

    def repo_exists(self, project_key, repository_slug):
        """
        Check if given combination of project and repository exists and available.
        :param project_key: Key of the project where to check for repository.
        :param repository_slug: url-compatible repository identifier to look for.
        :return: False is requested repository doesn't exist in the project or not accessible to the requestor
        """
        exists = False
        try:
            self.get_repo(project_key, repository_slug)
            exists = True
        except HTTPError as e:
            if e.response.status_code in (401, 404):
                pass
        return exists

    def update_repo(self, project_key, repository_slug, **params):
        """
        Update a repository in a project. This operates based on slug not name which may
        be confusing to some users.
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :return: The value of the put request.
        """
        url = self._url_repo(project_key, repository_slug)
        return self.put(url, data=params)

    def delete_repo(self, project_key, repository_slug):
        """
        Delete a specific repository from a project. This operates based on slug not name which may
        be confusing to some users.
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :return: Dictionary of request response
        """
        url = self._url_repo(project_key, repository_slug)
        return self.delete(url)

    def fork_repository(self, project_key, repository_slug, new_repository_slug):
        """
        Forks a repository within the same project.
        :param project_key:
        :param repository_slug:
        :param new_repository_slug:
        :return:
        """
        url = self._url_repo(project_key, repository_slug)
        body = {}
        if new_repository_slug is not None:
            body["name"] = new_repository_slug
            body["project"] = {"key": project_key}
        return self.post(url, data=body)

    def fork_repository_new_project(
        self,
        project_key,
        repository_slug,
        new_project_key,
        new_repository_slug,
    ):
        """
        Forks a repository to a separate project.
        :param project_key: Origin Project Key
        :param repository_slug: Origin repository slug
        :param new_project_key: Project Key of target project
        :param new_repository_slug: Target Repository slug
        :return:
        """
        url = self._url_repo(project_key, repository_slug)
        body = {}
        if new_repository_slug is not None and new_project_key is not None:
            body["name"] = new_repository_slug
            body["project"] = {"key": new_project_key}
        return self.post(url, data=body)

    def repo_keys(self, project_key, repo_key, start=0, limit=None, filter_str=None):
        """
        Get SSH access keys added to the repository
        :param start:
        :param limit:
        :param project_key: The project key
        :param repo_key: The repository key
        :param filter_str:  OPTIONAL: users filter string
        :return:
        """
        url = "{}/ssh".format(self._url_repo(project_key, repo_key, api_root="rest/keys"))
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def _url_repo_users(self, project_key, repo):
        return "{}/permissions/users".format(self._url_repo(project_key, repo))

    def repo_users(self, project_key, repo_key, start=0, limit=None, filter_str=None):
        """
        Get users with permission in repository
        :param start:
        :param limit:
        :param project_key: The project key
        :param repo_key: The repository key
        :param filter_str:  OPTIONAL: Users filter string
        :return:
        """
        url = self._url_repo_users(project_key, repo_key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def repo_grant_user_permissions(self, project_key, repo_key, username, permission):
        """
        Grant the specified repository permission to a specific user
        :param project_key: The project key
        :param repo_key: The repository key (slug)
        :param username: username to be granted
        :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
        :return:
        """
        url = self._url_repo_users(project_key, repo_key)
        params = {"permission": permission, "name": username}
        return self.put(url, params=params)

    def repo_remove_user_permissions(self, project_key, repo_key, username):
        """
        Revoke all permissions for the specified repository for a user.
        The authenticated user must have REPO_ADMIN permission for the specified repository
        or a higher project or global permission to call this resource.
        In addition, a user may not revoke their own repository permissions
        if they do not have a higher project or global permission.
        :param project_key: The project key
        :param repo_key: The repository key (slug)
        :param username: username to be granted
        :return:
        """
        url = self._url_repo_users(project_key, repo_key)
        params = {"name": username}
        return self.delete(url, params=params)

    def _url_repo_groups(self, project_key, repo):
        return "{}/permissions/groups".format(self._url_repo(project_key, repo))

    def repo_groups(self, project_key, repo_key, start=0, limit=None, filter_str=None):
        """
        Get repository Groups
        :param start:
        :param limit:
        :param project_key: The project key
        :param repo_key: The repository key
        :param filter_str: OPTIONAL: group filter string
        :return:
        """
        url = self._url_repo_groups(project_key, repo_key)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter_str:
            params["filter"] = filter_str
        return self._get_paged(url, params=params)

    def project_groups_with_administrator_permissions(self, key):
        """
        Get groups with admin permissions
        :param key:
        :return:
        """
        return [group["group"]["name"] for group in self.project_groups(key) if group["permission"] == "PROJECT_ADMIN"]

    def repo_users_with_administrator_permissions(self, project_key, repo_key):
        """
        Get repository administrators for repository
        :param project_key: The project key
        :param repo_key: The repository key
        :return: List of repo administrators
        """
        repo_administrators = []
        for user in self.repo_users(project_key, repo_key):
            if user["permission"] == "REPO_ADMIN":
                repo_administrators.append(user)
        for group in self.repo_groups_with_administrator_permissions(project_key, repo_key):
            for user in self.group_members(group):
                repo_administrators.append(user)
        for user in self.project_users_with_administrator_permissions(project_key):
            repo_administrators.append(user)
        # We convert to a set to ensure uniqueness then back to a list for later useability
        return list({user["id"]: user for user in repo_administrators}.values())

    def repo_groups_with_administrator_permissions(self, project_key, repo_key):
        """
        Get groups with admin permissions
        :param project_key:
        :param repo_key:
        :return:
        """
        repo_group_administrators = []
        for group in self.repo_groups(project_key, repo_key):
            if group["permission"] == "REPO_ADMIN":
                repo_group_administrators.append(group["group"]["name"])
        for group in self.project_groups_with_administrator_permissions(project_key):
            repo_group_administrators.append(group)
        # We convert to a set to ensure uniqueness, then back to a list for later useability
        return list(set(repo_group_administrators))

    def repo_grant_group_permissions(self, project_key, repo_key, groupname, permission):
        """
        Grant the specified repository permission to a specific group
        Promote or demote a group's permission level for the specified repository. Available repository permissions are:
            REPO_READ
            REPO_WRITE
            REPO_ADMIN
        See the Bitbucket Server documentation for a detailed explanation of what each permission entails.
        The authenticated user must have REPO_ADMIN permission for the specified repository or a higher project
        or global permission to call this resource.
        In addition, a user may not demote a group's permission level
        if their own permission level would be reduced as a result.
        :param project_key: The project key
        :param repo_key: The repository key (slug)
        :param groupname: group to be granted
        :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
        :return:
        """
        url = self._url_repo_groups(project_key, repo_key)
        params = {"permission": permission, "name": groupname}
        return self.put(url, params=params)

    def repo_remove_group_permissions(self, project_key, repo_key, groupname, permission):
        """
        Revoke all permissions for the specified repository for a group.
        The authenticated user must have REPO_ADMIN permission for the specified repository
        or a higher project or global permission to call this resource.
        In addition, a user may not revoke a group's permissions if it will reduce their own permission level.
        :param project_key: The project key
        :param repo_key: The repository key (slug)
        :param groupname: group to be granted
        :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
        :return:
        """
        url = self._url_repo_groups(project_key, repo_key)
        params = {"name": groupname}
        if permission:
            params["permission"] = permission
        return self.delete(url, params=params)

    def _url_repo_labels(self, project_key, repository_slug):
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")

        return "{}/labels".format(self._url_repo(project_key, repository_slug))

    def get_repo_labels(self, project_key, repository_slug):
        """
        Get labels for a specific repository from a project. This operates based on slug not name which may
        be confusing to some users. (BitBucket Server only)
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :return: Dictionary of request response
        """
        url = self._url_repo_labels(project_key, repository_slug)
        return self.get(url)

    def set_repo_label(self, project_key, repository_slug, label_name):
        """
        Sets a label on a repository. (BitBucket Server only)
        The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :param label_name: label name to apply
        :return:
        """
        url = self._url_repo_labels(project_key, repository_slug)
        data = {"name": label_name}
        return self.post(url, data=data)

    def _url_repo_audit_log(self, project_key, repository_slug):
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")

        return "{}/events".format(self._url_repo(project_key, repository_slug, api_root="rest/audit"))

    def get_repo_audit_log(self, project_key, repository_slug, start=0, limit=None):
        """
        Get the audit log of the repository
        :param start:
        :param limit:
        :param project_key: Key of the project you wish to look in.
        :param repository_slug: url-compatible repository identifier
        :return: List of events of the audit log
        """
        url = self._url_repo_audit_log(project_key, repository_slug)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def _url_repo_branches(self, project_key, repository_slug, api_root=None):
        return "{}/branches".format(self._url_repo(project_key, repository_slug, api_root=api_root))

    def get_branches(
        self,
        project_key,
        repository_slug,
        base=None,
        filter=None,
        start=0,
        limit=None,
        details=True,
        order_by="MODIFICATION",
        boost_matches=False,
    ):
        """
        Retrieve the branches matching the supplied filterText param.
        The authenticated user must have REPO_READ permission for the specified repository to call this resource.
        :param start:
        :param project_key:
        :param repository_slug:
        :param base: base branch/tag to compare each branch to (for the metadata providers that uses that information)
        :param filter:
        :param limit: OPTIONAL: The limit of the number of branches to return, this may be restricted by
                    fixed system limits. Default by built-in method: None
        :param details: whether to retrieve plugin-provided metadata about each branch
        :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
        :param boost_matches: Controls whether exact and prefix matches will be boosted to the top
        :return:
        """
        url = self._url_repo_branches(project_key, repository_slug)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter:
            params["filterText"] = filter
        if base:
            params["base"] = base
        if order_by:
            params["orderBy"] = order_by
        params["details"] = details
        params["boostMatches"] = boost_matches
        return self._get_paged(url, params=params)

    def _url_repo_default_branche(self, project_key, repository_slug):
        return "{}/default".format(self._url_repo_branches(project_key, repository_slug))

    def get_default_branch(self, project_key, repository_slug):
        """
        Get the default branch of the repository.
        The authenticated user must have REPO_READ permission for the specified repository to call this resource.
        :param project_key: The project key
        :param repository_slug: The repository key
        :return:
        """
        url = self._url_repo_default_branche(project_key, repository_slug)
        return self.get(url)

    def set_default_branch(self, project_key, repository_slug, ref_branch_name):
        """
        Update the default branch of a repository.
        The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
        :param project_key: The project key
        :param repository_slug: The repository key (slug)
        :param ref_branch_name: ref name like refs/heads/master
        :return:
        """
        url = self._url_repo_default_branche(project_key, repository_slug)
        data = {"id": ref_branch_name}
        return self.put(url, data=data)

    def create_branch(self, project_key, repository_slug, name, start_point, message=""):
        """Creates a branch using the information provided in the request.

        The authenticated user must have REPO_WRITE permission for the context repository to call this resource.

        :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
        :type project_key: str
        :param repository_slug: Name of repository where branch is created (i.e. "my_repo").
        :param name: Name of branch to create (i.e. "my_branch").
        :type name: str
        :param start_point: Name of branch to branch from.
        :type start_point: str
        :param message: Branch message.
        :type message: str
        :return:
            200 - application/json (repository)
            401 - application/json (errors)
            404 - application/json (errors)
        :rtype: requests.Response
        """
        url = self._url_repo_branches(project_key, repository_slug)
        data = {"name": name, "startPoint": start_point, "message": message}
        return self.post(url, data=data)

    def delete_branch(self, project_key, repository_slug, name, end_point=None):
        """
        Delete branch from related repo
        :param self:
        :param project_key:
        :param repository_slug:
        :param name:
        :param end_point:
        :return:
        """
        url = self._url_repo_branches(project_key, repository_slug, api_root="rest/branch-utils")
        data = {"name": str(name)}
        if end_point:
            data["endPoint"] = end_point
        return self.delete(url, data=data)

    def _url_repo_tags(self, project_key, repository_slug, api_root=None):
        if self.cloud:
            return "{}/refs/tags".format(self._url_repo(project_key, repository_slug, api_root=api_root))
        else:
            return "{}/tags".format(self._url_repo(project_key, repository_slug, api_root=api_root))

    def get_tags(
        self,
        project_key,
        repository_slug,
        filter="",
        limit=1000,
        order_by=None,
        start=0,
    ):
        """
        Retrieve the tags matching the supplied filterText param.
        The authenticated user must have REPO_READ permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param filter:
        :param start:
        :param limit: OPTIONAL: The limit of the number of tags to return, this may be restricted by
                fixed system limits. Default by built-in method: 1000
        :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
        :return:
        """
        url = self._url_repo_tags(project_key, repository_slug)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        if filter:
            params["filterText"] = filter
        if order_by:
            params["orderBy"] = order_by
        return self._get_paged(url, params=params)

    def get_project_tags(self, project_key, repository_slug, tag_name=None):
        """
        Retrieve a tag in the specified repository.
        The authenticated user must have REPO_READ permission for the context repository to call this resource.
        Search uri is api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*}
        :param project_key:
        :param repository_slug:
        :param tag_name: OPTIONAL:
        :return:
        """
        url = self._url_repo_tags(project_key, repository_slug)
        if tag_name is not None:
            return self.get("{}/{}".format(url, tag_name))

        return self._get_paged(url)

    def set_tag(
        self,
        project_key,
        repository_slug,
        tag_name,
        commit_revision,
        description=None,
    ):
        """
        Creates a tag using the information provided in the {@link RestCreateTagRequest request}
        The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param tag_name:
        :param commit_revision: commit hash
        :param description: OPTIONAL:
        :return:
        """
        url = self._url_repo_tags(project_key, repository_slug)
        body = {
            "name": tag_name,
            "startPoint": commit_revision,
        }
        if description is not None:
            body["message"] = description

        return self.post(url, data=body)

    def delete_tag(self, project_key, repository_slug, tag_name):
        """
        Creates a tag using the information provided in the {@link RestCreateTagRequest request}
        The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param tag_name:
        :return:
        """
        url = "{}/{}".format(
            self._url_repo_tags(project_key, repository_slug, api_root="rest/git"),
            tag_name,
        )
        return self.delete(url)

    def _url_repo_hook_settings(self, project_key, repository_slug):
        return "{}/settings/hooks".format(self._url_repo(project_key, repository_slug))

    def all_repo_hook_settings(
        self,
        project_key,
        repository_slug,
        start=0,
        limit=None,
        filter_type=None,
    ):
        """
        Get all repository hooks for a given repo
        :param project_key: The project key
        :param repository_slug: The repository key
        :param start:
        :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
                fixed system limits. Default by built-in method: None
        :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present,
                                    controls how repository hooks should be filtered.
        :return:
        """
        url = self._url_repo_hook_settings(project_key, repository_slug)
        params = {}
        if filter_type:
            params["type"] = filter_type
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def get_repo_hook_settings(self, project_key, repository_slug, hook_key):
        """
        Get a repository hook from a given repo
        :param project_key: The project key
        :param repository_slug: The repository key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}".format(
            self._url_repo_hook_settings(project_key, repository_slug),
            hook_key,
        )
        return self.get(url)

    def enable_repo_hook_settings(self, project_key, repository_slug, hook_key):
        """
        Enable a repository hook for a given repo
        :param project_key: The project key
        :param repository_slug: The repository key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}/enabled".format(
            self._url_repo_hook_settings(project_key, repository_slug),
            hook_key,
        )
        return self.put(url)

    def disable_repo_hook_settings(self, project_key, repository_slug, hook_key):
        """
        Disable a repository hook for a given repo
        :param project_key: The project key
        :param repository_slug: The repository key
        :param hook_key: The repository hook key
        :return:
        """
        url = "{}/{}/enabled".format(
            self._url_repo_hook_settings(project_key, repository_slug),
            hook_key,
        )
        return self.delete(url)

    def _url_webhooks(self, project_key, repository_slug):
        return "{}/webhooks".format(self._url_repo(project_key, repository_slug))

    def get_webhooks(
        self,
        project_key,
        repository_slug,
        event=None,
        statistics=False,
    ):
        """
        Get webhooks
        :param project_key:
        :param repository_slug:
        :param event: OPTIONAL: defaults to None
        :param statistics: OPTIONAL: defaults to False
        :return:
        """
        url = self._url_webhooks(project_key, repository_slug)
        params = {}
        if event:
            params["event"] = event
        if statistics:
            params["statistics"] = statistics
        return self._get_paged(url, params=params)

    def create_webhook(
        self,
        project_key,
        repository_slug,
        name,
        events,
        webhook_url,
        active,
        secret=None,
    ):
        """Creates a webhook using the information provided in the request.

        The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.

        :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
        :param repository_slug:
        :param name: Name of webhook to create.
        :param events: List of event. (i.e. ["repo:refs_changed", "pr:merged", "pr:opened"])
        :param webhook_url:
        :param active:
        :param secret: The string is used to verify data integrity between Bitbucket and your endpoint.
        :return:
        """
        url = self._url_webhooks(project_key, repository_slug)
        body = {
            "name": name,
            "events": events,
            "url": webhook_url,
            "active": active,
        }
        if secret:
            body["configuration"] = {"secret": secret}
        return self.post(url, data=body)

    def _url_webhook(self, project_key, repository_slug, webhook_id):
        return "{}/{}".format(self._url_webhooks(project_key, repository_slug), webhook_id)

    def get_webhook(self, project_key, repository_slug, webhook_id):
        """
        Retrieve a webhook.
        The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param webhook_id: the ID of the webhook within the repository
        :return:
        """
        url = self._url_webhook(project_key, repository_slug, webhook_id)
        return self.get(url)

    def update_webhook(self, project_key, repository_slug, webhook_id, **params):
        """
        Update a webhook.
        The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param webhook_id: the ID of the webhook within the repository
        :return:
        """
        url = self._url_webhook(project_key, repository_slug, webhook_id)
        return self.put(url, data=params)

    def delete_webhook(self, project_key, repository_slug, webhook_id):
        """
        Delete a webhook.
        The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param webhook_id: the ID of the webhook within the repository
        :return:
        """
        url = self._url_webhook(project_key, repository_slug, webhook_id)
        return self.delete(url)

    def _url_pull_request_settings(self, project_key, repository_slug):
        return "{}/settings/pull-requests".format(self._url_repo(project_key, repository_slug))

    def get_pull_request_settings(self, project_key, repository_slug):
        """
        Get pull request settings.
        :param project_key:
        :param repository_slug:
        :return:
        """
        url = self._url_pull_request_settings(project_key, repository_slug)
        return self.get(url)

    def set_pull_request_settings(self, project_key, repository_slug, data):
        """
        Set pull request settings.
        :param project_key:
        :param repository_slug:
        :param data: json body
        :return:
        """
        url = self._url_pull_request_settings(project_key, repository_slug)
        return self.post(url, data=data)

    def _url_pull_requests(self, project_key, repository_slug):
        if self.cloud:
            return self.resource_url("repositories/{}/{}/pullrequests".format(project_key, repository_slug))
        else:
            return "{}/pull-requests".format(self._url_repo(project_key, repository_slug))

    def get_pull_requests(
        self,
        project_key,
        repository_slug,
        state="OPEN",
        order="newest",
        limit=100,
        start=0,
        at=None,
    ):
        """
        Get pull requests
        :param project_key:
        :param repository_slug:
        :param state:
        :param order: OPTIONAL: defaults to NEWEST the order to return pull requests in, either OLDEST
                                (as in: "oldest first") or NEWEST.
        :param limit:
        :param start:
        :param at:
        :return:
        """
        url = self._url_pull_requests(project_key, repository_slug)
        params = {}
        if state:
            params["state"] = state
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start
        if order:
            params["order"] = order
        if at:
            params["at"] = at
        return self._get_paged(url, params=params)

    def get_required_reviewers_for_pull_request(
        self, source_project, source_repo, dest_project, dest_repo, source_branch, dest_branch
    ):
        """
        Get required reviewers for PR creation
        :param source_project: the project that the PR source is from
        :param source_repo: the repository that the PR source is from
        :param source_branch: the branch name of the PR
        :param dest_project: the project that the PR destination is from
        :param dest_repo: the repository that the PR destination is from
        :param dest_branch: where the PR is being merged into
        :return:
        """
        url = "{}/reviewers".format(
            self._url_repo(
                dest_project,
                dest_repo,
                api_root="rest/default-reviewers",
                api_version="1.0",
            )
        )
        source_repo_id = self.get_repo(source_project, source_repo)["id"]
        dest_repo_id = self.get_repo(dest_project, dest_repo)["id"]
        params = {
            "sourceRepoId": source_repo_id,
            "sourceRefId": source_branch,
            "targetRepoId": dest_repo_id,
            "targetRefId": dest_branch,
        }
        return self.get(url, params=params)

    def open_pull_request(
        self,
        source_project,
        source_repo,
        dest_project,
        dest_repo,
        source_branch,
        destination_branch,
        title,
        description,
        reviewers=None,
        include_required_reviewers=False,
    ):
        """
        Create a new pull request between two branches.
        The branches may be in the same repository_slug, or different ones.
        When using different repositories, they must still be in the same {@link Repository#getHierarchyId() hierarchy}.
        The authenticated user must have REPO_READ permission for the "from" and "to"repositories to call this resource.
        :param source_project: the project that the PR source is from
        :param source_repo: the repository that the PR source is from
        :param dest_project: the project that the PR destination is from
        :param dest_repo: the repository that the PR destination is from
        :param source_branch: the branch name of the PR
        :param destination_branch: where the PR is being merged into
        :param title: the title of the PR
        :param description: the description of what the PR does
        :param reviewers: the list of reviewers or a single reviewer of the PR
        :param include_required_reviewers: OPTIONAL defaults to False, include required reviewers for the PR
        :return:
        """
        body = {
            "title": title,
            "description": description,
            "fromRef": {
                "id": source_branch,
                "repository": {
                    "slug": source_repo,
                    "name": source_repo,
                    "project": {"key": source_project},
                },
            },
            "toRef": {
                "id": destination_branch,
                "repository": {
                    "slug": dest_repo,
                    "name": dest_repo,
                    "project": {"key": dest_project},
                },
            },
            "reviewers": [],
        }

        def add_reviewer(reviewer_name):
            entry = {"user": {"name": reviewer_name}}
            body["reviewers"].append(entry)

        if not self.cloud and include_required_reviewers:
            required_reviewers = self.get_required_reviewers_for_pull_request(
                source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch
            )
            for required_reviewer in required_reviewers:
                add_reviewer(required_reviewer["name"])

        if reviewers is not None:
            if isinstance(reviewers, str):
                add_reviewer(reviewers)
            elif isinstance(reviewers, list):
                for reviewer in reviewers:
                    add_reviewer(reviewer)

        return self.create_pull_request(dest_project, dest_repo, body)

    def create_pull_request(self, project_key, repository_slug, data):
        """
        :param project_key:
        :param repository_slug:
        :param data: json body
        :return:
        """
        url = self._url_pull_requests(project_key, repository_slug)
        return self.post(url, data=data)

    def _url_pull_request(self, project_key, repository_slug, pull_request_id):
        return "{}/{}".format(
            self._url_pull_requests(project_key, repository_slug),
            pull_request_id,
        )

    def get_pull_request(self, project_key, repository_slug, pull_request_id):
        """
        Retrieve a pull request.
        The authenticated user must have REPO_READ permission
        for the repository that this pull request targets to call this resource.
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :return:
        """
        url = self._url_pull_request(project_key, repository_slug, pull_request_id)
        return self.get(url)

    @deprecated(version="1.15.1", reason="Use get_pull_request()")
    def get_pullrequest(self, *args, **kwargs):
        """
        Deprecated name since 1.15.1. Let's use the get_pull_request()
        """

    def update_pull_request(self, project_key, repository_slug, pull_request_id, data):
        """
        Update a pull request.
        The authenticated user must have REPO_WRITE permission
        for the repository that this pull request targets to call this resource.
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :param data: json body
        :return:
        """

        url = self._url_pull_request(project_key, repository_slug, pull_request_id)
        return self.put(url, data=data)

    def delete_pull_request(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        pull_request_version,
    ):
        """
        Delete a pull request.

        :param project_key: the project key
        :param repository_slug: the repository slug
        :param pull_request_id: the ID of the pull request within the repository
        :param pull_request_version: the version of the pull request
        :return:
        """
        url = self._url_pull_request(project_key, repository_slug, pull_request_id)
        data = {"version": pull_request_version}
        return self.delete(url, data=data)

    def get_pull_requests_activities(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        start=0,
        limit=None,
    ):
        """
        Get pull requests activities
        :param limit:
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :param start:
        :return:
        """
        if self.cloud:
            url = "{}/activity".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        else:
            url = "{}/activities".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def get_pull_requests_changes(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        start=0,
        limit=None,
    ):
        """
        Get pull requests changes
        :param start:
        :param limit:
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :return:
        """
        url = "{}/changes".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def get_pull_requests_commits(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        start=0,
        limit=None,
    ):
        """
        Get pull requests commits
        :param start:
        :param limit:
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :start
        :limit
        :return:
        """
        url = "{}/commits".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def _url_pull_request_participants(self, project_key, repository_slug, pull_request_id):
        return "{}/{}/participants".format(
            self._url_pull_requests(project_key, repository_slug),
            pull_request_id,
        )

    def get_pull_requests_participants(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        start=0,
        limit=None,
    ):
        """
        Get all participants of a pull request
        :param start:
        :param limit:
        :param project_key:
        :param repository_slug:
        :param pull_request_id:
        :return:
        """
        url = self._url_pull_request_participants(project_key, repository_slug, pull_request_id)
        params = {}
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params)

    def get_dashboard_pull_requests(
        self,
        start=0,
        limit=None,
        closed_since=None,
        role=None,
        participant_status=None,
        state=None,
        order=None,
    ):
        """
        Get all pull requests where the current authenticated user is
        involved as either a reviewer, author or a participant
        :param start:
        :param limit:
        :param closed_since: OPTIONAL, defaults to returning pull
                             requests regardless of closed since date. Permits
                             returning only pull requests with a closed timestamp set more
                             recently that (now - closedSince). Units are in seconds. So
                             for example if closed since 86400 is set only pull requests
                             closed in the previous 24 hours will be returned.
        :param role: OPTIONAL, defaults to returning pull requests for
                     any role. If a role is supplied only pull requests where the
                     authenticated user is a participant in the given role will be
                     returned. Either REVIEWER, AUTHOR or PARTICIPANT.
        :param participant_status: OPTIONAL, defaults to returning
                                   pull requests with any participant status. A comma separated
                                   list of participant status. That is, one or more of
                                   UNAPPROVED, NEEDS_WORK, or APPROVED.
        :param state: OPTIONAL, defaults to returning pull requests in
                      any state. If a state is supplied only pull requests in the
                      specified state will be returned. Either OPEN, DECLINED or
                      MERGED. Omit this parameter to return pull request in any
                      state.

        :param order: OPTIONAL, defaults to NEWEST, the order to
                      return pull requests in, either OLDEST (as in: "oldest
                      first"), NEWEST, PARTICIPANT_STATUS, or CLOSED_DATE. Where
                      CLOSED_DATE is specified and the result set includes pull
                      requests that are not in the closed state, these pull requests
                      will appear first in the result set, followed by most recently
                      closed pull requests.
        :return:
        """
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")
        url = self.resource_url("dashboard/pull-requests")
        params = {}
        if start:
            params["start"] = start
        if limit is not None:
            params["limit"] = limit
        if closed_since is not None:
            params["closedSince"] = closed_since
        if role is not None:
            params["role"] = role
        if participant_status is not None:
            params["participantStatus"] = participant_status
        if state is not None:
            params["state"] = state
        if order is not None:
            params["order"] = order
        return self._get_paged(url, params=params)

    def change_reviewed_status(self, project_key, repository_slug, pull_request_id, status, user_slug):
        """
        Change the current user's status for a pull request.
        Implicitly adds the user as a participant if they are not already.
        If the current user is the author, this method will fail.
        :param project_key
        :param repository_slug:
        :param pull_request_id:
        :param status:
        :param user_slug:
        :return:
        """
        url = "{}/{}".format(
            self._url_pull_request_participants(project_key, repository_slug, pull_request_id),
            user_slug,
        )
        approved = True if status == "APPROVED" else False
        data = {
            "user": {"name": user_slug},
            "approved": approved,
            "status": status,
        }
        return self.put(url, data)

    def _url_pull_request_comments(self, project_key, repository_slug, pull_request_id):
        url = "{}/comments".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        return url

    def add_pull_request_comment(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        text,
        parent_id=None,
    ):
        """
        Add comment into pull request
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :param text comment text
        :param parent_id parent comment id

        :return:
        """
        url = self._url_pull_request_comments(project_key, repository_slug, pull_request_id)
        body = {"text": text}
        if parent_id:
            body["parent"] = {"id": parent_id}
        return self.post(url, data=body)

    def _url_pull_request_comment(self, project_key, repository_slug, pull_request_id, comment_id):
        url = "{}/{}".format(
            self._url_pull_request_comments(project_key, repository_slug, pull_request_id),
            comment_id,
        )
        return url

    def get_pull_request_comment(self, project_key, repository_slug, pull_request_id, comment_id):
        """
        Retrieves a pull request comment.
        The authenticated user must have REPO_READ permission
        for the repository that this pull request targets to call this resource.
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :param comment_id: the ID of the comment to retrieve
        :return:
        """
        url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
        return self.get(url)

    def update_pull_request_comment(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        comment_id,
        comment,
        comment_version,
    ):
        """
        Update the text of a comment.
        Only the user who created a comment may update it.

        Note: the supplied JSON object must contain a version
        that must match the server's version of the comment
        or the update will fail.
        """
        url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
        data = {"version": comment_version, "text": comment}
        return self.put(url, data=data)

    @deprecated(version="2.4.2", reason="Use delete_pull_request_comment()")
    def delete_pull_reques_comment(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        comment_id,
        comment_version,
    ):
        """
        Deprecated name since 2.4.2. Let's use the get_pull_request()
        """
        return self.delete_pull_request_comment(
            project_key,
            repository_slug,
            pull_request_id,
            comment_id,
            comment_version,
        )

    def delete_pull_request_comment(
        self,
        project_key,
        repository_slug,
        pull_request_id,
        comment_id,
        comment_version,
    ):
        """
        Delete a comment.
        Only the repository admin or user who created a comment may update it.

        Note: the supplied JSON object must contain a version
        that must match the server's version of the comment
        or delete will fail.
        """
        url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
        data = {"version": comment_version}
        return self.delete(url, params=data)

    def decline_pull_request(self, project_key, repository_slug, pr_id, pr_version):
        """
        Decline a pull request.
        The authenticated user must have REPO_READ permission for the repository
        that this pull request targets to call this resource.

        :param project_key: PROJECT
        :param repository_slug: my_shiny_repo
        :param pr_id: 2341
        :param pr_version: 12
        :return:
        """
        url = "{}/decline".format(self._url_pull_request(project_key, repository_slug, pr_id))
        params = {}
        if not self.cloud:
            params["version"] = pr_version
        return self.post(url, params=params)

    def get_tasks(self, project_key, repository_slug, pull_request_id):
        """
        Get all tasks for the pull request
        :param project_key:
        :param repository_slug:
        :param pull_request_id: the ID of the pull request within the repository
        :return:
        """
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")
        url = "{}/tasks".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
        return self.get(url)

    def _url_tasks(self):
        if self.cloud:
            raise Exception("Not supported in Bitbucket Cloud")
        return self.resource_url("tasks")

    def add_task(self, anchor, text):
        """
        Add task to the comment
        :param anchor: ID of the comment,
        :param text: task text
        :return:
        """
        url = self._url_tasks()
        data = {"anchor": {"id": anchor, "type": "COMMENT"}, "text": text}
        return self.post(url, data=data)

    def _url_task(self, task_id):
        return "{}/{}".format(self._url_tasks(), task_id)

    def get_task(self, task_id):
        """
        Get task information by ID
        :param task_id:
        :return:
        """
        url = self._url_task(task_id)
        return self.get(url)

    def delete_task(self, task_id):
        """
        Delete task by ID
        :param task_id:
        :return:
        """
        url = self._url_task(task_id)
        return self.delete(url)

    def update_task(self, task_id, text=None, state=None):
        """
        Update task by ID. It is possible to update state and/or text of the task
        :param task_id:
        :param text:
        :param state: OPEN, RESOLVED
        :return:
        """
        url = self._url_task(task_id)
        data = {"id": task_id}
        if text:
            data["text"] = text
        if state:
            data["state"] = state
        return self.put(url, data=data)

    def is_pull_request_can_be_merged(self, project_key, repository_slug, pr_id):
        """
        Test whether a pull request can be merged.
        A pull request may not be merged if:
        - there are conflicts that need to be manually resolved before merging; and/or
        - one or more merge checks have vetoed the merge.
        The authenticated user must have REPO_READ permission for the repository
        that this pull request targets to call this resource.

        :param project_key: PROJECT
        :param repository_slug: my_shiny_repo
        :param pr_id: 2341
        :return:
        """
        url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id))
        return self.get(url)

    def merge_pull_request(self, project_key, repository_slug, pr_id, pr_version):
        """
        Merge pull request
        The authenticated user must have REPO_READ permission for the repository
        that this pull request targets to call this resource.

        :param project_key: PROJECT
        :param repository_slug: my_shiny_repo
        :param pr_id: 2341
        :param pr_version:
        :return:
        """
        url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id))
        params = {}
        if not self.cloud:
            params["version"] = pr_version
        return self.post(url, params=params)

    def reopen_pull_request(self, project_key, repository_slug, pr_id, pr_version):
        """
        Re-open a declined pull request.
        The authenticated user must have REPO_READ permission for the repository
        that this pull request targets to call this resource.

        :param project_key: PROJECT
        :param repository_slug: my_shiny_repo
        :param pr_id: 2341
        :param pr_version: 12
        :return:
        """
        url = "{}/reopen".format(self._url_pull_request(project_key, repository_slug, pr_id))
        params = {"version": pr_version}
        return self.post(url, params=params)

    def _url_inbox_pull_requests(self):
        return "inbox/pull-requests"

    def check_inbox_pull_requests_count(self):
        url = "{}/count".format(self._url_inbox_pull_requests())
        return self.get(url)

    def check_inbox_pull_requests(self, start=0, limit=None, role=None):
        """
        Get pull request in your inbox
        :param start:
        :param limit:
        :param role:
        :return:
        """
        url = self._url_inbox_pull_requests()
        params = {"start": start}
        if limit:
            params["limit"] = limit
        if role:
            params["role"] = role
        return self._get_paged(url, params=params)

    def _url_repo_compare(self, project_key, repository_slug):
        url = "{}/compare".format(self._url_repo(project_key, repository_slug))
        return url

    def get_diff(self, project_key, repository_slug, path, hash_oldest, hash_newest):
        """
        Gets a diff of the changes available in the {@code from} commit but not in the {@code to} commit.
        If either the {@code from} or {@code to} commit are not specified,
        they will be replaced by the default branch of their containing repository.
        :param project_key:
        :param repository_slug:
        :param path:
        :param hash_oldest: the source commit (can be a partial/full commit ID or qualified/unqualified ref name)
        :param hash_newest: the target commit (can be a partial/full commit ID or qualified/unqualified ref name)
        :return:
        """
        url = "{}/diff/{}".format(self._url_repo_compare(project_key, repository_slug), path)
        params = {}
        if hash_oldest:
            params["from"] = hash_oldest
        if hash_newest:
            params["to"] = hash_newest
        return (self.get(url, params=params) or {}).get("diffs")

    def _url_commits(self, project_key, repository_slug, api_root=None, api_version=None):
        return "{}/commits".format(
            self._url_repo(
                project_key,
                repository_slug,
                api_root=api_root,
                api_version=api_version,
            )
        )

    def get_commits(
        self,
        project_key,
        repository_slug,
        hash_oldest=None,
        hash_newest=None,
        follow_renames=False,
        ignore_missing=False,
        merges="include",
        with_counts=False,
        avatar_size=None,
        avatar_scheme=None,
        limit=None,
        until=None,
        since=None,
    ):
        """
        Get commit list from repo
        :param project_key:
        :param repository_slug:
        :param hash_oldest:
        :param hash_newest:
        :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered.
        :param follow_renames: OPTIONAL: if true, the commit history of the specified file will be followed past renames
        :param ignore_missing: OPTIONAL: true to ignore missing commits, false otherwise
        :param with_counts: OPTIONAL: optionally include the total number of commits and total number of unique authors
        :param avatar_size: OPTIONAL: if present the service adds avatar URLs for commit authors.
        :param avatar_scheme: OPTIONAL: the desired scheme for the avatar URL
        :param limit: OPTIONAL: The limit of the number of commits to return, this may be restricted by
               fixed system limits. Default by built-in method: None
        :param until: OPTIONAL: The commit ID or ref (inclusively) to retrieve commits before
        :param since: OPTIONAL: The commit ID or ref (exclusively) to retrieve commits after
        :return:
        """
        url = self._url_commits(project_key, repository_slug)
        params = {"merges": merges}
        if hash_oldest:
            params["since"] = hash_oldest
        if hash_newest:
            params["until"] = hash_newest
        if follow_renames:
            params["followRenames"] = follow_renames
        if ignore_missing:
            params["ignoreMissing"] = ignore_missing
        if with_counts:
            params["withCounts"] = with_counts
        if avatar_size:
            params["avatarSize"] = avatar_size
        if avatar_scheme:
            params["avatarScheme"] = avatar_scheme
        if limit:
            params["limit"] = limit
        if self.cloud and (since or until):
            raise Exception("Not supported in Bitbucket Cloud")
        if since:
            params["since"] = since
        if until:
            params["until"] = until
        return self._get_paged(url, params=params)

    def get_commit_changes(self, project_key, repository_slug, hash_newest=None, merges="include", commit_id=None):
        """
        Get commit list from repo
        :param project_key:
        :param repository_slug:
        :param hash_newest:
        :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered.
        :param commit_id
        :return:
        """
        url = self._url_commit_c(project_key, repository_slug, commit_id=commit_id)
        params = {"merges": merges}
        if hash_newest:
            params["until"] = hash_newest
        return self.get(url, params=params)

    def _url_commit_c(self, project_key, repository_slug, api_root=None, api_version=None, commit_id=None):
        return "{}/commits/{}/changes".format(
            self._url_repo(
                project_key,
                repository_slug,
                api_root=api_root,
                api_version=api_version,
            ),
            commit_id,
        )

    def _url_commit(
        self,
        project_key,
        repository_slug,
        commit_id,
        api_root=None,
        api_version=None,
    ):
        return "{}/{}".format(
            self._url_commits(
                project_key,
                repository_slug,
                api_root=api_root,
                api_version=api_version,
            ),
            commit_id,
        )

    def get_commit_info(self, project_key, repository_slug, commit, path=None):
        """
        Retrieve a single commit identified by its ID>. In general, that ID is a SHA1.
        From 2.11, ref names like "refs/heads/master" are no longer accepted by this resource.
        The authenticated user must have REPO_READ permission for the specified repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param commit: the commit ID to retrieve
        :param path :OPTIONAL an optional path to filter the commit by.
                        If supplied the details returned may not be for the specified commit.
                        Instead, starting from the specified commit, they will be the details for the first commit
                        affecting the specified path.
        :return:
        """

        url = self._url_commit(project_key, repository_slug, commit)
        params = {}
        if path:
            params["path"] = path
        return self.get(url, params=params)

    def _url_commit_pull_requests(self, project_key, repository_slug, commit_id):
        return "{}/pull-requests".format(self._url_commit(project_key, repository_slug, commit_id))

    def get_pull_requests_contain_commit(self, project_key, repository_slug, commit):
        url = self._url_commit_pull_requests(project_key, repository_slug, commit)
        return (self.get(url) or {}).get("values")

    def get_changelog(
        self,
        project_key,
        repository_slug,
        ref_from,
        ref_to,
        start=0,
        limit=None,
    ):
        """
        Get change log between 2 refs
        :param start:
        :param project_key:
        :param repository_slug:
        :param ref_from:
        :param ref_to:
        :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
                fixed system limits. Default by built-in method: None
        :return:
        """
        url = "{}/compare/commits".format(self._url_repo(project_key, repository_slug))
        params = {}
        if ref_from:
            params["from"] = ref_from
        if ref_to:
            params["to"] = ref_to
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def _url_code_insights_annotations(self, project_key, repository_slug, commit_id, report_key):
        return "{}/reports/{}/annotations".format(
            self._url_commit(
                project_key,
                repository_slug,
                commit_id,
                api_root="rest/insights",
                api_version="1.0",
            ),
            report_key,
        )

    def add_code_insights_annotations_to_report(self, project_key, repository_slug, commit_id, report_key, annotations):
        """
        Adds annotations to an existing insight report.
        For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
        :project_key: str
        :repository_slug: str
        :commit_id: str
        :report_key: str
        :annotations: list
        """
        url = self._url_code_insights_annotations(project_key, repository_slug, commit_id, report_key)
        data = {"annotations": annotations}
        return self.post(url, data=data)

    def _url_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
        return "{}/reports/{}".format(
            self._url_commit(
                project_key,
                repository_slug,
                commit_id,
                api_root="rest/insights",
                api_version="1.0",
            ),
            report_key,
        )

    def get_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
        """
        Retrieve the specified code-insights report.
        :projectKey: str
        :repositorySlug: str
        :commit_id: str
        :report_key: str
        """
        url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
        return self.get(url)

    def delete_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
        """
        Delete a report for the given commit. Also deletes any annotations associated with this report.
        :projectKey: str
        :repositorySlug: str
        :commit_id: str
        :report_key: str
        """
        url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
        return self.delete(url)

    def create_code_insights_report(
        self,
        project_key,
        repository_slug,
        commit_id,
        report_key,
        report_title,
        **report_params
    ):  # fmt: skip
        """
        Create a new insight report, or replace the existing one
        if a report already exists for the given repository_slug, commit, and report key.
        A request to replace an existing report will be rejected
        if the authenticated user was not the creator of the specified report.
        For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
        :projectKey: str
        :repositorySlug: str
        :commitId: str
        :report_key: str
        :report_title: str
        :report_params:
        """
        url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
        data = {"title": report_title}
        data.update(report_params)
        return self.put(url, data=data)

    def get_file_list(
        self,
        project_key,
        repository_slug,
        sub_folder=None,
        query=None,
        start=0,
        limit=None,
    ):
        """
        Retrieve a page of files from particular directory of a repository.
        The search is done recursively, so all files from any subdirectory of the specified directory will be returned.
        The authenticated user must have REPO_READ permission for the specified repository to call this resource.
        :param start:
        :param project_key:
        :param repository_slug:
        :param sub_folder: a sub folder in the target repository to list the files from.
        :param query: the commit ID or ref (e.g. a branch or tag) to list the files at.
                      If not specified the default branch will be used instead.
        :param limit: OPTIONAL
        :return:
        """
        url = "{}/files".format(self._url_repo(project_key, repository_slug))
        if sub_folder:
            url = "{}/{}".format(url, sub_folder.lstrip("/"))
        params = {}
        if query:
            params["at"] = query
        if start:
            params["start"] = start
        if limit:
            params["limit"] = limit
        return self._get_paged(url, params=params)

    def get_content_of_file(self, project_key, repository_slug, filename, at=None, markup=None):
        """
        Retrieve the raw content for a file path at a specified revision.
        The authenticated user must have REPO_READ permission for the specified repository to call this resource.
        :param project_key:
        :param repository_slug:
        :param filename:
        :param at: OPTIONAL ref string
        :param markup: if present or "true", triggers the raw content to be markup-rendered and returned as HTML;
            otherwise, if not specified, or any value other than "true" the content is streamed without markup.
        :return:
        """
        url = "{}/raw/{}".format(self._url_repo(project_key, repository_slug), filename)
        params = {}
        if at is not None:
            params["at"] = at
        if markup is not None:
            params["markup"] = markup
        headers = self.form_token_headers
        return self.get(url, params=params, not_json_response=True, headers=headers)

    def _url_branches_permissions(self, project_key, permission_id=None, repository_slug=None):
        if repository_slug is None:
            base = self._url_project(
                project_key,
                api_root="rest/branch-permissions",
                api_version="2.0",
            )
        else:
            base = self._url_repo(
                project_key,
                repository_slug,
                api_root="rest/branch-permissions",
                api_version="2.0",
            )

        return "{}/restrictions/{}".format(base, "" if permission_id is None else str(permission_id))

    def get_branches_permissions(
        self,
        project_key,
        permission_id,
        repository_slug=None,
        start=0,
        limit=25,
    ):
        """
        Get branches permissions from a given repo
        :param project_key:
        :param permission_id:
        :param repository_slug:
        :param start:
        :param limit:
        :return:
        """
        url = self._url_branches_permissions(project_key, permission_id, repository_slug)
        params = {}
        if limit:
            params["limit"] = limit
        if start:
            params["start"] = start
        return self.get(url, params=params)

    def set_branches_permissions(
        self,
        project_key,
        multiple_permissions=False,
        matcher_type=None,
        matcher_value=None,
        permission_type=None,
        repository_slug=None,
        except_users=None,
        except_groups=None,
        except_access_keys=None,
        start=0,
        limit=25,
    ):
        """
        Create a restriction for the supplied branch or set of branches to be applied to the given repository.
        Allows creating multiple restrictions at once.
        To use multiple restrictions you should format payload manually -
        see the bitbucket-branch-restrictions.py example.
        Reference: https://docs.atlassian.com/bitbucket-server/rest/6.8.0/bitbucket-ref-restriction-rest.html
        :param project_key:
        :param multiple_permissions:
        :param matcher_type:
        :param matcher_value:
        :param permission_type:
        :param repository_slug:
        :param except_users:
        :param except_groups:
        :param except_access_keys:
        :param start:
        :param limit:
        :return:
        """
        url = self._url_branches_permissions(project_key=project_key, repository_slug=repository_slug)
        if except_users is None:
            except_users = []
        if except_groups is None:
            except_groups = []
        if except_access_keys is None:
            except_access_keys = []
        headers = self.default_headers
        if multiple_permissions:
            headers = self.bulk_headers
            restriction = multiple_permissions
        else:
            restriction = {
                "type": permission_type,
                "matcher": {
                    "id": matcher_value,
                    "displayId": matcher_value,
                    "type": {
                        "id": matcher_type.upper(),
                        "name": matcher_type.capitalize(),
                    },
                    "active": True,
                },
                "users": except_users,
                "groups": except_groups,
                "accessKeys": except_access_keys,
            }
        params = {"start": start, "limit": limit}
        return self.post(url, data=restriction, params=params, headers=headers)

    def delete_branch_permission(self, project_key, permission_id, repository_slug=None):
        """
        Deletes a restriction as specified by a restriction id.
        The authenticated user must have REPO_ADMIN permission or higher to call this resource.

        :param project_key:
        :param repository_slug:
        :param permission_id:
        :return:
        """
        url = self._url_branches_permissions(project_key, permission_id, repository_slug)
        return self.delete(url)

    def get_branch_permission(self, project_key, permission_id, repository_slug=None):
        """
        Returns a restriction as specified by a restriction id.
        The authenticated user must have REPO_ADMIN permission or higher to call this resource.

        :param project_key:
        :param repository_slug:
        :param permission_id:
        :return:
        """
        url = self._url_branches_permissions(project_key, permission_id, repository_slug)
        return self._get_paged(url)

    def all_branches_permissions(self, project_key, permission_id, repository_slug=None):
        """
        Get branches permissions from a given repo
        :param project_key:
        :param permission_id
        :param repository_slug:
        :return:
        """
        url = self._url_branches_permissions(project_key, permission_id, repository_slug)
        return self._get_paged(url)

    def _url_branching_model(self, project_key, repository_slug):
        return "{}/branchmodel/configuration".format(
            self._url_repo(
                project_key,
                repository_slug,
                api_root="rest/branch-utils",
                api_version="1.0",
            )
        )

    def get_branching_model(self, project_key, repository_slug):
        """
        Get branching model
        :param project_key:
        :param repository_slug:
        :return:
        """
        url = self._url_branching_model(project_key, repository_slug)
        return self.get(url)

    def set_branching_model(self, project_key, repository_slug, data):
        """
        Set branching model
        :param project_key:
        :param repository_slug:
        :param data:
        :return:
        """
        url = self._url_branching_model(project_key, repository_slug)
        return self.put(url, data=data)

    def enable_branching_model(self, project_key, repository_slug):
        """
        Enable branching model by setting it with default configuration
        :param project_key:
        :param repository_slug:
        :return:
        """
        default_model_data = {
            "development": {"refId": None, "useDefault": True},
            "types": [
                {
                    "displayName": "Bugfix",
                    "enabled": True,
                    "id": "BUGFIX",
                    "prefix": "bugfix/",
                },
                {
                    "displayName": "Feature",
                    "enabled": True,
                    "id": "FEATURE",
                    "prefix": "feature/",
                },
                {
                    "displayName": "Hotfix",
                    "enabled": True,
                    "id": "HOTFIX",
                    "prefix": "hotfix/",
                },
                {
                    "displayName": "Release",
                    "enabled": True,
                    "id": "RELEASE",
                    "prefix": "release/",
                },
            ],
        }
        return self.set_branching_model(project_key, repository_slug, default_model_data)

    def disable_branching_model(self, project_key, repository_slug):
        """
        Disable branching model
        :param project_key:
        :param repository_slug:
        :return:
        """
        return self.delete(self._url_branching_model(project_key, repository_slug))

    def _url_file(self, project_key, repository_slug, filename):
        return "{}/browse/{}".format(self._url_repo(project_key, repository_slug), filename)

    def upload_file(self, project_key, repository_slug, content, message, branch, filename):
        """
        Upload new file for given branch.
        :param project_key:
        :param repository_slug:
        :param content:
        :param message:
        :param branch:
        :param filename
        :return:
        """
        url = self._url_file(project_key, repository_slug, filename)
        data = {"content": content, "message": message, "branch": branch}
        return self.put(url, files=data, headers={"Accept": "application/json"})

    def update_file(
        self,
        project_key,
        repository_slug,
        content,
        message,
        branch,
        filename,
        source_commit_id,
    ):
        """
        Update existing file for given branch.
        :param project_key:
        :param repository_slug:
        :param content:
        :param message:
        :param branch:
        :param filename:
        :param source_commit_id:
        :return:
        """
        url = self._url_file(project_key, repository_slug, filename)
        data = {
            "content": content,
            "message": message,
            "branch": branch,
            "sourceCommitId": source_commit_id,
        }
        return self.put(url, files=data, headers={"Accept": "application/json"})

    def search_code(self, team, search_query, page=1, limit=10):
        """
        Search repositories for matching code
        :team: str
        :search_query: str
        """
        url = self.resource_url("teams/{team}/search/code".format(team=team))
        return self.get(
            url,
            params={"search_query": search_query, "page": page, "pagelen": limit},
        )

    def get_lfs_repo_status(self, project_key, repo):
        url = "rest/git-lfs/admin/projects/{projectKey}/repos/{repositorySlug}/enabled".format(
            projectKey=project_key, repositorySlug=repo
        )
        return self.get(url)

    def set_lfs_repo_status(self, project_key, repo, enable=True):
        url = "rest/git-lfs/admin/projects/{projectKey}/repos/{repositorySlug}/enabled".format(
            projectKey=project_key, repositorySlug=repo
        )
        if enable:
            return self.put(url)
        else:
            return self.delete(url)

    def _url_repo_conditions(self, project_key, repo_key):
        return "{}/conditions".format(
            self._url_repo(
                project_key,
                repo_key,
                api_root="rest/default-reviewers",
                api_version="1.0",
            )
        )

    def get_repo_conditions(self, project_key, repo_key):
        """
        Request type: GET
        Return a page of defaults conditions with reviewers list (type REPOSITORY or PROJECT)
        that have been configured for this repository slug inside project specified.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :return:
        """
        url = self._url_repo_conditions(project_key, repo_key)
        return self.get(url) or {}

    def get_repo_project_conditions(self, project_key, repo_key):
        """
        Request type: GET
        Return a page of repository conditions (only type PROJECT) with reviewers list associated
        that have been configured for this repository slug inside project specified.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :return:
        """
        response = self.get_repo_conditions(project_key, repo_key)
        count = 0
        for condition in response:
            if condition["scope"]["type"] == "REPOSITORY":
                del response[count]
            count += 1
        return response

    def get_repo_repo_conditions(self, project_key, repo_key):
        """
        Request type: GET
        Return a page of repository conditions (only type REPOSITORY) with reviewers list associated
        that have been configured for this repository slug inside project specified.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :return:
        """
        response = self.get_repo_conditions(project_key, repo_key)
        count = 0
        for condition in response:
            if condition["scope"]["type"] == "PROJECT":
                del response[count]
            count += 1
        return response

    def _url_repo_condition(self, project_key, repo_key, id_condition=None):
        return "{}/condition/{}".format(
            self._url_repo(
                project_key,
                repo_key,
                api_root="rest/default-reviewers",
                api_version="1.0",
            ),
            "" if id_condition is None else str(id_condition),
        )

    def get_repo_condition(self, project_key, repo_key, id_condition):
        """
        Request type: GET
        Return a specific condition with reviewers list
            that have been configured for this repository slug inside project specified.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :idCondition: int - condition id involved
        :return:
        """
        url = self._url_repo_condition(project_key, repo_key, id_condition)
        return self.get(url) or {}

    def create_repo_condition(self, project_key, repo_key, condition):
        """
        Request type: POST
        Create a new condition for this repository slug inside project specified.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264908128
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :data: condition: dictionary object
        :example condition: '{"sourceMatcher":
                                {"id":"any",
                                "type":{"id":"ANY_REF"}},
                                "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                                "reviewers":[{"id": 12}],"requiredApprovals":"0"
                            }'
        :return:
        """
        url = self._url_repo_condition(project_key, repo_key)
        return self.post(url, data=condition) or {}

    def update_repo_condition(self, project_key, repo_key, condition, id_condition):
        """
        Request type: PUT
        Update a specific condition for this repository slug inside project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :idCondition: int - condition id involved
        :data: condition: dictionary object
        :example condition: '{"sourceMatcher":
                                {"id":"any",
                                "type":{"id":"ANY_REF"}},
                                "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                                "reviewers":[{"id": 12}],"requiredApprovals":"0"
                            }'
        :return:
        """
        url = self._url_repo_condition(project_key, repo_key, id_condition)
        return self.put(url, data=condition) or {}

    def delete_repo_condition(self, project_key, repo_key, id_condition):
        """
        Delete a specific condition for this repository slug inside project.
        For further information visit:
            https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm8287339888
        Request type: DELETE
        :projectKey: str- project key involved
        :repoKey: str - repo key involved
        :idCondition: int - condition id involved
        :return:
        """
        url = self._url_repo_condition(project_key, repo_key, id_condition)
        return self.delete(url) or {}

    def download_repo_archive(
        self,
        project_key,
        repository_slug,
        dest_fd,
        at=None,
        filename=None,
        format=None,
        path=None,
        prefix=None,
        chunk_size=128,
    ):
        """
        Downloads a repository archive.
        Note that the data is written to the specified file-like object,
        rather than simply being returned.
        For further information visit:
           https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp199
        :param project_key:
        :param repository_slug:
        :param dest_fd: a file-like object to which the archive will be written
        :param at: string: Optional, the commit to download an archive of; if not supplied,
                         an archive of the default branch is downloaded
        :param filename: string: Optional, a filename to include the "Content-Disposition" header
        :param format: string: Optional, the format to stream the archive in; must be one of: zip, tar, tar.gz or tgz.
                    If not specified, then the archive will be in zip format.
        :param path: string: Optional, path to include in the streamed archive
        :param prefix: string: Optional, a prefix to apply to all entries in the streamed archive;
                    if the supplied prefix does not end with a trailing /, one will be added automatically
        :param chunk_size: int: Optional, download chunk size. Defeault is 128
        """
        url = "{}/archive".format(self._url_repo(project_key, repository_slug))
        params = {}
        if at is not None:
            params["at"] = at
        if filename is not None:
            params["filename"] = filename
        if format is not None:
            params["format"] = format
        if path is not None:
            params["path"] = path
        if prefix is not None:
            params["prefix"] = prefix
        headers = {"Accept": "*/*"}
        response = self.get(url, params=params, headers=headers, advanced_mode=True)
        for chunk in response.iter_content(chunk_size=chunk_size):
            dest_fd.write(chunk)

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_repositories(self, workspace, role=None, query=None, sort=None):
        """
        Get all repositories in a workspace.

        :param workspace:
        :param role: Filters the result based on the authenticated user's role on each repository.
                      One of: member, contributor, admin, owner
        :param query: Query string to narrow down the response.
        :param sort: Field by which the results should be sorted.
        """
        return [
            r.data
            for r in Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.each(role=role, q=query, sort=sort)
        ]

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_pipelines(self, workspace, repository_slug, number=10, sort_by="-created_on"):
        """
        Get information about latest pipelines runs.

        :param workspace:
        :param repository_slug:
        :param sort_by:
        :param number: number of pipelines to fetch
        :param :sort_by: optional key to sort available pipelines for
        :return: List of pipeline data
        """
        values = []
        for p in (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.each(sort=sort_by)
        ):
            values.append(p.data)
            if len(values) == number:
                break

        return values

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def trigger_pipeline(
        self,
        workspace,
        repository_slug,
        branch="master",
        revision=None,
        name=None,
    ):
        """
        Trigger a new pipeline. The following options are possible (1 and 2
        trigger the pipeline that the branch is associated with in the Pipelines
        configuration):
        1. Latest revision of a branch (specify ``branch``)
        2. Specific revision on a branch (additionally specify ``revision``)
        3. Specific pipeline (additionally specify ``name``)
        :return: the initiated pipeline; or error information
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.trigger(branch=branch, commit=revision, pattern=name)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_pipeline(self, workspace, repository_slug, uuid):
        """
        Get information about the pipeline specified by ``uuid``.
        :param workspace:
        :param repository_slug:
        :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.get(uuid)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def stop_pipeline(self, workspace, repository_slug, uuid):
        """
        Stop the pipeline specified by ``uuid``.
        :param workspace:
        :param repository_slug:
        :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)

        See the documentation for the meaning of response status codes.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.get(uuid)
            .stop()
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_pipeline_steps(self, workspace, repository_slug, uuid):
        """
        Get information about the steps of the pipeline specified by ``uuid``.
        :param workspace:
        :param repository_slug:
        :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)
        """
        values = []
        for s in (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.get(uuid)
            .steps()
        ):
            values.append(s.data)

        return values

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_pipeline_step(self, workspace, repository_slug, pipeline_uuid, step_uuid):
        """
        Get information about a step of a pipeline, specified by respective UUIDs.
        :param workspace:
        :param repository_slug:
        :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number)
        :param step_uuid: Step identifier (with surrounding {})
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.get(pipeline_uuid)
            .step(step_uuid)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_pipeline_step_log(self, workspace, repository_slug, pipeline_uuid, step_uuid):
        """
        Get log of a step of a pipeline, specified by respective UUIDs.
        :param workspace:
        :param repository_slug:
        :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number)
        :param step_uuid: Step identifier (with surrounding {})
        :return: byte string log
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .pipelines.get(pipeline_uuid)
            .step(step_uuid)
            .log()
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def create_issue(
        self,
        workspace,
        repository_slug,
        title,
        description="",
        kind="bug",
        priority="major",
    ):
        """
        Create a new issue in the issue tracker of the given repository.
        :param workspace:
        :param repository_slug:
        :param title:
        :param description:
        :param kind: one of: bug, enhancement, proposal, task
        :param priority: one of: trivial, minor, major, critical, blocker
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .issues.create(
                title=title,
                description=description,
                kind=kind,
                priority=priority,
            )
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_issues(self, workspace, repository_slug, sort_by=None, query=None):
        """
        Get information about the issues tracked in the given repository. By
        default, the issues are sorted by ID in descending order.
        :param workspace:
        :param repository_slug:
        :param sort_by: optional key to sort available issues for
        :param query: optional query to filter available issues for. See
          https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
          for an overview

        :return: List of issues (direct, i.e. without the 'values' key)
        """
        values = []
        for p in (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .issues.each(q=query, sort=sort_by)
        ):
            values.append(p.data)

        return values

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_issue(self, workspace, repository_slug, id):
        """
        Get the issue specified by ``id``.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .issues.get(id)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def update_issue(self, workspace, repository_slug, id, **fields):
        """
        Update the ``fields`` of the issue specified by ``id``.
        Consult the official API documentation for valid fields.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .issues.get(id)
            .update(**fields)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def delete_issue(self, workspace, repository_slug, id):
        """
        Delete the issue specified by ``id``.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .issues.get(id)
            .delete()
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def add_branch_restriction(
        self,
        workspace,
        repository_slug,
        kind,
        branch_match_kind="glob",
        branch_pattern="*",
        branch_type=None,
        users=None,
        groups=None,
        value=None,
    ):
        """
        Add a new branch restriction.

        :param workspace:
        :param repository_slug:
        :param value:
        :param kind: One of require_tasks_to_be_completed, force, restrict_merges,
                      enforce_merge_checks, require_approvals_to_merge, delete,
                      require_all_dependencies_merged, push, require_passing_builds_to_merge,
                      reset_pullrequest_approvals_on_change, require_default_reviewer_approvals_to_merge
        :param branch_match_kind: branching_model or glob, if branching_model use
                      param branch_type otherwise branch_pattern.
        :param branch_pattern: A glob specifying the branch this restriction should
                      apply to (supports * as wildcard).
        :param branch_type: The branch type specifies the branches this restriction
                      should apply to. One of: feature, bugfix, release, hotfix, development, production.
        :param users: List of user objects that are excluded from the restriction.
                        Minimal: {"username": "<username>"}
        :param groups: List of group objects that are excluded from the restriction.
                        Minimal: {"owner": {"username": "<teamname>"}, "slug": "<groupslug>"}
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .branch_restrictions.create(
                kind,
                branch_match_kind=branch_match_kind,
                branch_pattern=branch_pattern,
                branch_type=branch_type,
                users=users,
                groups=groups,
                value=value,
            )
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_branch_restrictions(self, workspace, repository_slug, kind=None, pattern=None, number=10):
        """
        Get all branch permissions.
        """
        values = []
        for p in (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .branch_restrictions.each(kind=kind, pattern=pattern)
        ):
            values.append(p.data)
            if len(values) == number:
                break

        return values

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def update_branch_restriction(self, workspace, repository_slug, id, **fields):
        """
        Update an existing branch restriction identified by ``id``.
        Consult the official API documentation for valid fields.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .branch_restrictions.get(id)
            .update(**fields)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def delete_branch_restriction(self, workspace, repository_slug, id):
        """
        Delete an existing branch restriction identified by ``id``.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .branch_restrictions.get(id)
            .delete()
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def add_default_reviewer(self, workspace, repository_slug, user):
        """
        Add user as default reviewer to the repository.
        Can safely be called multiple times with the same user, only adds once.

        :param workspace:
        :param repository_slug:
        :param user: The username or account UUID to add as default_reviewer.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .default_reviewers.add(user)
            .data
        )

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def get_default_reviewers(self, workspace, repository_slug, number=10):
        """
        Get all default reviewers for the repository.
        """
        values = []
        for p in (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .default_reviewers.each()
        ):
            values.append(p.data)
            if len(values) == number:
                break

        return values

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def is_default_reviewer(self, workspace, repository_slug, user):
        """
        Check if the user is a default reviewer of the repository.

        :param workspace:
        :param repository_slug:
        :param user: The username or account UUID to check.
        :return: True if present, False if not.
        """
        if (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .default_reviewers.get(user)
            is None
        ):
            return False

        return True

    @deprecated(
        version="2.0.2",
        reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
    )
    def delete_default_reviewer(self, workspace, repository_slug, user):
        """
        Remove user as default reviewer from the repository.

        :param repository_slug:
        :param workspace:
        :param user: The username or account UUID to delete as default reviewer.
        """
        return (
            Cloud(self.url, **self._new_session_args)
            .workspaces.get(workspace)
            .repositories.get(repository_slug)
            .default_reviewers.get(user)
            .delete()
        )

add_branch_restriction(workspace, repository_slug, kind, branch_match_kind='glob', branch_pattern='*', branch_type=None, users=None, groups=None, value=None)

Add a new branch restriction.

:param workspace: :param repository_slug: :param value: :param kind: One of require_tasks_to_be_completed, force, restrict_merges, enforce_merge_checks, require_approvals_to_merge, delete, require_all_dependencies_merged, push, require_passing_builds_to_merge, reset_pullrequest_approvals_on_change, require_default_reviewer_approvals_to_merge :param branch_match_kind: branching_model or glob, if branching_model use param branch_type otherwise branch_pattern. :param branch_pattern: A glob specifying the branch this restriction should apply to (supports * as wildcard). :param branch_type: The branch type specifies the branches this restriction should apply to. One of: feature, bugfix, release, hotfix, development, production. :param users: List of user objects that are excluded from the restriction. Minimal: {"username": ""} :param groups: List of group objects that are excluded from the restriction. Minimal: {"owner": {"username": ""}, "slug": ""}

Source code in server/vendor/atlassian/bitbucket/__init__.py
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def add_branch_restriction(
    self,
    workspace,
    repository_slug,
    kind,
    branch_match_kind="glob",
    branch_pattern="*",
    branch_type=None,
    users=None,
    groups=None,
    value=None,
):
    """
    Add a new branch restriction.

    :param workspace:
    :param repository_slug:
    :param value:
    :param kind: One of require_tasks_to_be_completed, force, restrict_merges,
                  enforce_merge_checks, require_approvals_to_merge, delete,
                  require_all_dependencies_merged, push, require_passing_builds_to_merge,
                  reset_pullrequest_approvals_on_change, require_default_reviewer_approvals_to_merge
    :param branch_match_kind: branching_model or glob, if branching_model use
                  param branch_type otherwise branch_pattern.
    :param branch_pattern: A glob specifying the branch this restriction should
                  apply to (supports * as wildcard).
    :param branch_type: The branch type specifies the branches this restriction
                  should apply to. One of: feature, bugfix, release, hotfix, development, production.
    :param users: List of user objects that are excluded from the restriction.
                    Minimal: {"username": "<username>"}
    :param groups: List of group objects that are excluded from the restriction.
                    Minimal: {"owner": {"username": "<teamname>"}, "slug": "<groupslug>"}
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .branch_restrictions.create(
            kind,
            branch_match_kind=branch_match_kind,
            branch_pattern=branch_pattern,
            branch_type=branch_type,
            users=users,
            groups=groups,
            value=value,
        )
        .data
    )

add_code_insights_annotations_to_report(project_key, repository_slug, commit_id, report_key, annotations)

Adds annotations to an existing insight report. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html :project_key: str :repository_slug: str :commit_id: str :report_key: str :annotations: list

Source code in server/vendor/atlassian/bitbucket/__init__.py
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
def add_code_insights_annotations_to_report(self, project_key, repository_slug, commit_id, report_key, annotations):
    """
    Adds annotations to an existing insight report.
    For further information visit:
    https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
    :project_key: str
    :repository_slug: str
    :commit_id: str
    :report_key: str
    :annotations: list
    """
    url = self._url_code_insights_annotations(project_key, repository_slug, commit_id, report_key)
    data = {"annotations": annotations}
    return self.post(url, data=data)

add_default_reviewer(workspace, repository_slug, user)

Add user as default reviewer to the repository. Can safely be called multiple times with the same user, only adds once.

:param workspace: :param repository_slug: :param user: The username or account UUID to add as default_reviewer.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def add_default_reviewer(self, workspace, repository_slug, user):
    """
    Add user as default reviewer to the repository.
    Can safely be called multiple times with the same user, only adds once.

    :param workspace:
    :param repository_slug:
    :param user: The username or account UUID to add as default_reviewer.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .default_reviewers.add(user)
        .data
    )

add_pull_request_comment(project_key, repository_slug, pull_request_id, text, parent_id=None)

Add comment into pull request :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :param text comment text :param parent_id parent comment id

:return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
def add_pull_request_comment(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    text,
    parent_id=None,
):
    """
    Add comment into pull request
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :param text comment text
    :param parent_id parent comment id

    :return:
    """
    url = self._url_pull_request_comments(project_key, repository_slug, pull_request_id)
    body = {"text": text}
    if parent_id:
        body["parent"] = {"id": parent_id}
    return self.post(url, data=body)

add_task(anchor, text)

Add task to the comment :param anchor: ID of the comment, :param text: task text :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
def add_task(self, anchor, text):
    """
    Add task to the comment
    :param anchor: ID of the comment,
    :param text: task text
    :return:
    """
    url = self._url_tasks()
    data = {"anchor": {"id": anchor, "type": "COMMENT"}, "text": text}
    return self.post(url, data=data)

all_branches_permissions(project_key, permission_id, repository_slug=None)

Get branches permissions from a given repo :param project_key: :param permission_id :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
def all_branches_permissions(self, project_key, permission_id, repository_slug=None):
    """
    Get branches permissions from a given repo
    :param project_key:
    :param permission_id
    :param repository_slug:
    :return:
    """
    url = self._url_branches_permissions(project_key, permission_id, repository_slug)
    return self._get_paged(url)

all_project_administrators()

Get the list of project administrators

:return: A generator object containing a map with the project_key, project_name and project_administrators

Source code in server/vendor/atlassian/bitbucket/__init__.py
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def all_project_administrators(self):
    """
    Get the list of project administrators

    :return: A generator object containing a map with the project_key, project_name and project_administrators
    """
    for project in self.project_list():
        log.info("Processing project: %s - %s", project.get("key"), project.get("name"))
        yield {
            "project_key": project.get("key"),
            "project_name": project.get("name"),
            "project_administrators": [
                {"email": x["emailAddress"], "name": x["displayName"]}
                for x in self.project_users_with_administrator_permissions(project["key"])
            ],
        }

all_project_repo_hook_settings(project_key, start=0, limit=None, filter_type=None)

Get all repository hooks for a given project :param project_key: The project key :param start: :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by fixed system limits. Default by built-in method: None :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present, controls how repository hooks should be filtered. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
def all_project_repo_hook_settings(self, project_key, start=0, limit=None, filter_type=None):
    """
    Get all repository hooks for a given project
    :param project_key: The project key
    :param start:
    :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
            fixed system limits. Default by built-in method: None
    :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present,
                                controls how repository hooks should be filtered.
    :return:
    """
    url = self._url_project_repo_hook_settings(project_key)
    params = {}
    if filter_type:
        params["type"] = filter_type
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

all_repo_hook_settings(project_key, repository_slug, start=0, limit=None, filter_type=None)

Get all repository hooks for a given repo :param project_key: The project key :param repository_slug: The repository key :param start: :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by fixed system limits. Default by built-in method: None :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present, controls how repository hooks should be filtered. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
def all_repo_hook_settings(
    self,
    project_key,
    repository_slug,
    start=0,
    limit=None,
    filter_type=None,
):
    """
    Get all repository hooks for a given repo
    :param project_key: The project key
    :param repository_slug: The repository key
    :param start:
    :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
            fixed system limits. Default by built-in method: None
    :param filter_type: OPTIONAL: PRE_RECEIVE|POST_RECEIVE if present,
                                controls how repository hooks should be filtered.
    :return:
    """
    url = self._url_repo_hook_settings(project_key, repository_slug)
    params = {}
    if filter_type:
        params["type"] = filter_type
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

change_reviewed_status(project_key, repository_slug, pull_request_id, status, user_slug)

Change the current user's status for a pull request. Implicitly adds the user as a participant if they are not already. If the current user is the author, this method will fail. :param project_key :param repository_slug: :param pull_request_id: :param status: :param user_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
def change_reviewed_status(self, project_key, repository_slug, pull_request_id, status, user_slug):
    """
    Change the current user's status for a pull request.
    Implicitly adds the user as a participant if they are not already.
    If the current user is the author, this method will fail.
    :param project_key
    :param repository_slug:
    :param pull_request_id:
    :param status:
    :param user_slug:
    :return:
    """
    url = "{}/{}".format(
        self._url_pull_request_participants(project_key, repository_slug, pull_request_id),
        user_slug,
    )
    approved = True if status == "APPROVED" else False
    data = {
        "user": {"name": user_slug},
        "approved": approved,
        "status": status,
    }
    return self.put(url, data)

check_inbox_pull_requests(start=0, limit=None, role=None)

Get pull request in your inbox :param start: :param limit: :param role: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
def check_inbox_pull_requests(self, start=0, limit=None, role=None):
    """
    Get pull request in your inbox
    :param start:
    :param limit:
    :param role:
    :return:
    """
    url = self._url_inbox_pull_requests()
    params = {"start": start}
    if limit:
        params["limit"] = limit
    if role:
        params["role"] = role
    return self._get_paged(url, params=params)

check_reindexing_status()

Check reindexing status :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
106
107
108
109
110
111
112
def check_reindexing_status(self):
    """
    Check reindexing status
    :return:
    """
    url = self.resource_url("status", api_root="rest/indexing", api_version="latest")
    return self.get(url)

create_branch(project_key, repository_slug, name, start_point, message='')

Creates a branch using the information provided in the request.

The authenticated user must have REPO_WRITE permission for the context repository to call this resource.

:param project_key: The project matching the projectKey supplied in the resource path as shown in URL. :type project_key: str :param repository_slug: Name of repository where branch is created (i.e. "my_repo"). :param name: Name of branch to create (i.e. "my_branch"). :type name: str :param start_point: Name of branch to branch from. :type start_point: str :param message: Branch message. :type message: str :return: 200 - application/json (repository) 401 - application/json (errors) 404 - application/json (errors) :rtype: requests.Response

Source code in server/vendor/atlassian/bitbucket/__init__.py
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
def create_branch(self, project_key, repository_slug, name, start_point, message=""):
    """Creates a branch using the information provided in the request.

    The authenticated user must have REPO_WRITE permission for the context repository to call this resource.

    :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
    :type project_key: str
    :param repository_slug: Name of repository where branch is created (i.e. "my_repo").
    :param name: Name of branch to create (i.e. "my_branch").
    :type name: str
    :param start_point: Name of branch to branch from.
    :type start_point: str
    :param message: Branch message.
    :type message: str
    :return:
        200 - application/json (repository)
        401 - application/json (errors)
        404 - application/json (errors)
    :rtype: requests.Response
    """
    url = self._url_repo_branches(project_key, repository_slug)
    data = {"name": name, "startPoint": start_point, "message": message}
    return self.post(url, data=data)

create_code_insights_report(project_key, repository_slug, commit_id, report_key, report_title, **report_params)

Create a new insight report, or replace the existing one if a report already exists for the given repository_slug, commit, and report key. A request to replace an existing report will be rejected if the authenticated user was not the creator of the specified report. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html :projectKey: str :repositorySlug: str :commitId: str :report_key: str :report_title: str :report_params:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
def create_code_insights_report(
    self,
    project_key,
    repository_slug,
    commit_id,
    report_key,
    report_title,
    **report_params
):  # fmt: skip
    """
    Create a new insight report, or replace the existing one
    if a report already exists for the given repository_slug, commit, and report key.
    A request to replace an existing report will be rejected
    if the authenticated user was not the creator of the specified report.
    For further information visit:
    https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
    :projectKey: str
    :repositorySlug: str
    :commitId: str
    :report_key: str
    :report_title: str
    :report_params:
    """
    url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
    data = {"title": report_title}
    data.update(report_params)
    return self.put(url, data=data)

create_issue(workspace, repository_slug, title, description='', kind='bug', priority='major')

Create a new issue in the issue tracker of the given repository. :param workspace: :param repository_slug: :param title: :param description: :param kind: one of: bug, enhancement, proposal, task :param priority: one of: trivial, minor, major, critical, blocker

Source code in server/vendor/atlassian/bitbucket/__init__.py
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def create_issue(
    self,
    workspace,
    repository_slug,
    title,
    description="",
    kind="bug",
    priority="major",
):
    """
    Create a new issue in the issue tracker of the given repository.
    :param workspace:
    :param repository_slug:
    :param title:
    :param description:
    :param kind: one of: bug, enhancement, proposal, task
    :param priority: one of: trivial, minor, major, critical, blocker
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .issues.create(
            title=title,
            description=description,
            kind=kind,
            priority=priority,
        )
        .data
    )

create_project(key, name, description='')

Create project :param key: The project key :param name: The project name :param description: The project description

:return: The value of the post request.

Source code in server/vendor/atlassian/bitbucket/__init__.py
316
317
318
319
320
321
322
323
324
325
326
327
def create_project(self, key, name, description=""):
    """
    Create project
    :param key: The project key
    :param name: The project name
    :param description: The project description

    :return: The value of the post request.
    """
    url = self._url_projects()
    data = {"key": key, "name": name, "description": description}
    return self.post(url, data=data)

create_project_condition(project_key, condition)

Request type: POST Create a new condition for this project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264893584 :projectKey: str- project key involved :data: condition: dictionary object :example condition: '{"sourceMatcher": {"id":"any", "type":{"id":"ANY_REF"}}, "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}}, "reviewers":[{"id": 12}],"requiredApprovals":"0" }' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
def create_project_condition(self, project_key, condition):
    """
    Request type: POST
    Create a new condition for this project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264893584
    :projectKey: str- project key involved
    :data: condition: dictionary object
    :example condition: '{"sourceMatcher":
                            {"id":"any",
                            "type":{"id":"ANY_REF"}},
                            "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                            "reviewers":[{"id": 12}],"requiredApprovals":"0"
                        }'
    :return:
    """
    url = self._url_project_condition(project_key)
    return self.post(url, data=condition) or {}

create_pull_request(project_key, repository_slug, data)

:param project_key: :param repository_slug: :param data: json body :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1717
1718
1719
1720
1721
1722
1723
1724
1725
def create_pull_request(self, project_key, repository_slug, data):
    """
    :param project_key:
    :param repository_slug:
    :param data: json body
    :return:
    """
    url = self._url_pull_requests(project_key, repository_slug)
    return self.post(url, data=data)

create_repo(project_key, repository_slug, forkable=False, is_private=True)

Create a new repository.

Requires an existing project in which this repository will be created. The only parameters which will be used are name and scmId.

The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource.

:param project_key: The project matching the projectKey supplied in the resource path as shown in URL. :type project_key: str :param repository_slug: Name of repository to create (i.e. "My repo"). :param forkable: Set the repository to be forkable or not. :type forkable: bool :param is_private: Set the repository to be private or not. :type is_private: bool :return: 201 - application/json (repository) 400 - application/json (errors) 401 - application/json (errors) 409 - application/json (errors) :rtype: requests.Response

Source code in server/vendor/atlassian/bitbucket/__init__.py
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
def create_repo(self, project_key, repository_slug, forkable=False, is_private=True):
    """Create a new repository.

    Requires an existing project in which this repository will be created. The only parameters which will be used
    are name and scmId.

    The authenticated user must have PROJECT_ADMIN permission for the context project to call this resource.

    :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
    :type project_key: str
    :param repository_slug: Name of repository to create (i.e. "My repo").
    :param forkable: Set the repository to be forkable or not.
    :type forkable: bool
    :param is_private: Set the repository to be private or not.
    :type is_private: bool
    :return:
        201 - application/json (repository)
        400 - application/json (errors)
        401 - application/json (errors)
        409 - application/json (errors)
    :rtype: requests.Response
    """
    url = self._url_repos(project_key)
    data = {
        "name": repository_slug,
        "scmId": "git",
        "forkable": forkable,
        "is_private": is_private,
    }
    return self.post(url, data=data)

create_repo_condition(project_key, repo_key, condition)

Request type: POST Create a new condition for this repository slug inside project specified. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264908128 :projectKey: str- project key involved :repoKey: str - repo key involved :data: condition: dictionary object :example condition: '{"sourceMatcher": {"id":"any", "type":{"id":"ANY_REF"}}, "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}}, "reviewers":[{"id": 12}],"requiredApprovals":"0" }' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
def create_repo_condition(self, project_key, repo_key, condition):
    """
    Request type: POST
    Create a new condition for this repository slug inside project specified.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264908128
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :data: condition: dictionary object
    :example condition: '{"sourceMatcher":
                            {"id":"any",
                            "type":{"id":"ANY_REF"}},
                            "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                            "reviewers":[{"id": 12}],"requiredApprovals":"0"
                        }'
    :return:
    """
    url = self._url_repo_condition(project_key, repo_key)
    return self.post(url, data=condition) or {}

create_webhook(project_key, repository_slug, name, events, webhook_url, active, secret=None)

Creates a webhook using the information provided in the request.

The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.

:param project_key: The project matching the projectKey supplied in the resource path as shown in URL. :param repository_slug: :param name: Name of webhook to create. :param events: List of event. (i.e. ["repo:refs_changed", "pr:merged", "pr:opened"]) :param webhook_url: :param active: :param secret: The string is used to verify data integrity between Bitbucket and your endpoint. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
def create_webhook(
    self,
    project_key,
    repository_slug,
    name,
    events,
    webhook_url,
    active,
    secret=None,
):
    """Creates a webhook using the information provided in the request.

    The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.

    :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
    :param repository_slug:
    :param name: Name of webhook to create.
    :param events: List of event. (i.e. ["repo:refs_changed", "pr:merged", "pr:opened"])
    :param webhook_url:
    :param active:
    :param secret: The string is used to verify data integrity between Bitbucket and your endpoint.
    :return:
    """
    url = self._url_webhooks(project_key, repository_slug)
    body = {
        "name": name,
        "events": events,
        "url": webhook_url,
        "active": active,
    }
    if secret:
        body["configuration"] = {"secret": secret}
    return self.post(url, data=body)

decline_pull_request(project_key, repository_slug, pr_id, pr_version)

Decline a pull request. The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource.

:param project_key: PROJECT :param repository_slug: my_shiny_repo :param pr_id: 2341 :param pr_version: 12 :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
def decline_pull_request(self, project_key, repository_slug, pr_id, pr_version):
    """
    Decline a pull request.
    The authenticated user must have REPO_READ permission for the repository
    that this pull request targets to call this resource.

    :param project_key: PROJECT
    :param repository_slug: my_shiny_repo
    :param pr_id: 2341
    :param pr_version: 12
    :return:
    """
    url = "{}/decline".format(self._url_pull_request(project_key, repository_slug, pr_id))
    params = {}
    if not self.cloud:
        params["version"] = pr_version
    return self.post(url, params=params)

delete_announcement_banner()

Gets the announcement banner, if one exists and is available to the user :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
256
257
258
259
260
261
262
def delete_announcement_banner(self):
    """
    Gets the announcement banner, if one exists and is available to the user
    :return:
    """
    url = self._url_announcement_banner()
    return self.delete(url)

delete_branch(project_key, repository_slug, name, end_point=None)

Delete branch from related repo :param self: :param project_key: :param repository_slug: :param name: :param end_point: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
def delete_branch(self, project_key, repository_slug, name, end_point=None):
    """
    Delete branch from related repo
    :param self:
    :param project_key:
    :param repository_slug:
    :param name:
    :param end_point:
    :return:
    """
    url = self._url_repo_branches(project_key, repository_slug, api_root="rest/branch-utils")
    data = {"name": str(name)}
    if end_point:
        data["endPoint"] = end_point
    return self.delete(url, data=data)

delete_branch_permission(project_key, permission_id, repository_slug=None)

Deletes a restriction as specified by a restriction id. The authenticated user must have REPO_ADMIN permission or higher to call this resource.

:param project_key: :param repository_slug: :param permission_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
def delete_branch_permission(self, project_key, permission_id, repository_slug=None):
    """
    Deletes a restriction as specified by a restriction id.
    The authenticated user must have REPO_ADMIN permission or higher to call this resource.

    :param project_key:
    :param repository_slug:
    :param permission_id:
    :return:
    """
    url = self._url_branches_permissions(project_key, permission_id, repository_slug)
    return self.delete(url)

delete_branch_restriction(workspace, repository_slug, id)

Delete an existing branch restriction identified by id.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def delete_branch_restriction(self, workspace, repository_slug, id):
    """
    Delete an existing branch restriction identified by ``id``.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .branch_restrictions.get(id)
        .delete()
    )

delete_code_insights_report(project_key, repository_slug, commit_id, report_key)

Delete a report for the given commit. Also deletes any annotations associated with this report. :projectKey: str :repositorySlug: str :commit_id: str :report_key: str

Source code in server/vendor/atlassian/bitbucket/__init__.py
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
def delete_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
    """
    Delete a report for the given commit. Also deletes any annotations associated with this report.
    :projectKey: str
    :repositorySlug: str
    :commit_id: str
    :report_key: str
    """
    url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
    return self.delete(url)

delete_default_reviewer(workspace, repository_slug, user)

Remove user as default reviewer from the repository.

:param repository_slug: :param workspace: :param user: The username or account UUID to delete as default reviewer.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def delete_default_reviewer(self, workspace, repository_slug, user):
    """
    Remove user as default reviewer from the repository.

    :param repository_slug:
    :param workspace:
    :param user: The username or account UUID to delete as default reviewer.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .default_reviewers.get(user)
        .delete()
    )

delete_issue(workspace, repository_slug, id)

Delete the issue specified by id.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def delete_issue(self, workspace, repository_slug, id):
    """
    Delete the issue specified by ``id``.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .issues.get(id)
        .delete()
    )

delete_project_condition(project_key, id_condition)

Delete a specific condition for this repository slug inside project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264896304 Request type: DELETE :projectKey: str- project key involved :idCondition: int - condition id involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
716
717
718
719
720
721
722
723
724
725
726
727
def delete_project_condition(self, project_key, id_condition):
    """
    Delete a specific condition for this repository slug inside project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264896304
    Request type: DELETE
    :projectKey: str- project key involved
    :idCondition: int - condition id involved
    :return:
    """
    url = self._url_project_condition(project_key, id_condition)
    return self.delete(url) or {}

delete_pull_reques_comment(project_key, repository_slug, pull_request_id, comment_id, comment_version)

Deprecated name since 2.4.2. Let's use the get_pull_request()

Source code in server/vendor/atlassian/bitbucket/__init__.py
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
@deprecated(version="2.4.2", reason="Use delete_pull_request_comment()")
def delete_pull_reques_comment(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    comment_id,
    comment_version,
):
    """
    Deprecated name since 2.4.2. Let's use the get_pull_request()
    """
    return self.delete_pull_request_comment(
        project_key,
        repository_slug,
        pull_request_id,
        comment_id,
        comment_version,
    )

delete_pull_request(project_key, repository_slug, pull_request_id, pull_request_version)

Delete a pull request.

:param project_key: the project key :param repository_slug: the repository slug :param pull_request_id: the ID of the pull request within the repository :param pull_request_version: the version of the pull request :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
def delete_pull_request(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    pull_request_version,
):
    """
    Delete a pull request.

    :param project_key: the project key
    :param repository_slug: the repository slug
    :param pull_request_id: the ID of the pull request within the repository
    :param pull_request_version: the version of the pull request
    :return:
    """
    url = self._url_pull_request(project_key, repository_slug, pull_request_id)
    data = {"version": pull_request_version}
    return self.delete(url, data=data)

delete_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id, comment_version)

Delete a comment. Only the repository admin or user who created a comment may update it.

Note: the supplied JSON object must contain a version that must match the server's version of the comment or delete will fail.

Source code in server/vendor/atlassian/bitbucket/__init__.py
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
def delete_pull_request_comment(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    comment_id,
    comment_version,
):
    """
    Delete a comment.
    Only the repository admin or user who created a comment may update it.

    Note: the supplied JSON object must contain a version
    that must match the server's version of the comment
    or delete will fail.
    """
    url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
    data = {"version": comment_version}
    return self.delete(url, params=data)

delete_repo(project_key, repository_slug)

Delete a specific repository from a project. This operates based on slug not name which may be confusing to some users. :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :return: Dictionary of request response

Source code in server/vendor/atlassian/bitbucket/__init__.py
885
886
887
888
889
890
891
892
893
894
def delete_repo(self, project_key, repository_slug):
    """
    Delete a specific repository from a project. This operates based on slug not name which may
    be confusing to some users.
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :return: Dictionary of request response
    """
    url = self._url_repo(project_key, repository_slug)
    return self.delete(url)

delete_repo_condition(project_key, repo_key, id_condition)

Delete a specific condition for this repository slug inside project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm8287339888 Request type: DELETE :projectKey: str- project key involved :repoKey: str - repo key involved :idCondition: int - condition id involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
def delete_repo_condition(self, project_key, repo_key, id_condition):
    """
    Delete a specific condition for this repository slug inside project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm8287339888
    Request type: DELETE
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :idCondition: int - condition id involved
    :return:
    """
    url = self._url_repo_condition(project_key, repo_key, id_condition)
    return self.delete(url) or {}

delete_tag(project_key, repository_slug, tag_name)

Creates a tag using the information provided in the {@link RestCreateTagRequest request} The authenticated user must have REPO_WRITE permission for the context repository to call this resource. :param project_key: :param repository_slug: :param tag_name: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
def delete_tag(self, project_key, repository_slug, tag_name):
    """
    Creates a tag using the information provided in the {@link RestCreateTagRequest request}
    The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param tag_name:
    :return:
    """
    url = "{}/{}".format(
        self._url_repo_tags(project_key, repository_slug, api_root="rest/git"),
        tag_name,
    )
    return self.delete(url)

delete_task(task_id)

Delete task by ID :param task_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2155
2156
2157
2158
2159
2160
2161
2162
def delete_task(self, task_id):
    """
    Delete task by ID
    :param task_id:
    :return:
    """
    url = self._url_task(task_id)
    return self.delete(url)

delete_webhook(project_key, repository_slug, webhook_id)

Delete a webhook. The authenticated user must have REPO_ADMIN permission for the context repository to call this resource. :param project_key: :param repository_slug: :param webhook_id: the ID of the webhook within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
def delete_webhook(self, project_key, repository_slug, webhook_id):
    """
    Delete a webhook.
    The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param webhook_id: the ID of the webhook within the repository
    :return:
    """
    url = self._url_webhook(project_key, repository_slug, webhook_id)
    return self.delete(url)

disable_branching_model(project_key, repository_slug)

Disable branching model :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2808
2809
2810
2811
2812
2813
2814
2815
def disable_branching_model(self, project_key, repository_slug):
    """
    Disable branching model
    :param project_key:
    :param repository_slug:
    :return:
    """
    return self.delete(self._url_branching_model(project_key, repository_slug))

disable_project_repo_hook_settings(project_key, hook_key)

Disable a repository hook for a given project :param project_key: The project key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
621
622
623
624
625
626
627
628
629
def disable_project_repo_hook_settings(self, project_key, hook_key):
    """
    Disable a repository hook for a given project
    :param project_key: The project key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}/enabled".format(self._url_project_repo_hook_settings(project_key), hook_key)
    return self.delete(url)

disable_repo_hook_settings(project_key, repository_slug, hook_key)

Disable a repository hook for a given repo :param project_key: The project key :param repository_slug: The repository key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
def disable_repo_hook_settings(self, project_key, repository_slug, hook_key):
    """
    Disable a repository hook for a given repo
    :param project_key: The project key
    :param repository_slug: The repository key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}/enabled".format(
        self._url_repo_hook_settings(project_key, repository_slug),
        hook_key,
    )
    return self.delete(url)

download_repo_archive(project_key, repository_slug, dest_fd, at=None, filename=None, format=None, path=None, prefix=None, chunk_size=128)

Downloads a repository archive. Note that the data is written to the specified file-like object, rather than simply being returned. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp199 :param project_key: :param repository_slug: :param dest_fd: a file-like object to which the archive will be written :param at: string: Optional, the commit to download an archive of; if not supplied, an archive of the default branch is downloaded :param filename: string: Optional, a filename to include the "Content-Disposition" header :param format: string: Optional, the format to stream the archive in; must be one of: zip, tar, tar.gz or tgz. If not specified, then the archive will be in zip format. :param path: string: Optional, path to include in the streamed archive :param prefix: string: Optional, a prefix to apply to all entries in the streamed archive; if the supplied prefix does not end with a trailing /, one will be added automatically :param chunk_size: int: Optional, download chunk size. Defeault is 128

Source code in server/vendor/atlassian/bitbucket/__init__.py
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
def download_repo_archive(
    self,
    project_key,
    repository_slug,
    dest_fd,
    at=None,
    filename=None,
    format=None,
    path=None,
    prefix=None,
    chunk_size=128,
):
    """
    Downloads a repository archive.
    Note that the data is written to the specified file-like object,
    rather than simply being returned.
    For further information visit:
       https://docs.atlassian.com/bitbucket-server/rest/7.13.0/bitbucket-rest.html#idp199
    :param project_key:
    :param repository_slug:
    :param dest_fd: a file-like object to which the archive will be written
    :param at: string: Optional, the commit to download an archive of; if not supplied,
                     an archive of the default branch is downloaded
    :param filename: string: Optional, a filename to include the "Content-Disposition" header
    :param format: string: Optional, the format to stream the archive in; must be one of: zip, tar, tar.gz or tgz.
                If not specified, then the archive will be in zip format.
    :param path: string: Optional, path to include in the streamed archive
    :param prefix: string: Optional, a prefix to apply to all entries in the streamed archive;
                if the supplied prefix does not end with a trailing /, one will be added automatically
    :param chunk_size: int: Optional, download chunk size. Defeault is 128
    """
    url = "{}/archive".format(self._url_repo(project_key, repository_slug))
    params = {}
    if at is not None:
        params["at"] = at
    if filename is not None:
        params["filename"] = filename
    if format is not None:
        params["format"] = format
    if path is not None:
        params["path"] = path
    if prefix is not None:
        params["prefix"] = prefix
    headers = {"Accept": "*/*"}
    response = self.get(url, params=params, headers=headers, advanced_mode=True)
    for chunk in response.iter_content(chunk_size=chunk_size):
        dest_fd.write(chunk)

enable_branching_model(project_key, repository_slug)

Enable branching model by setting it with default configuration :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
def enable_branching_model(self, project_key, repository_slug):
    """
    Enable branching model by setting it with default configuration
    :param project_key:
    :param repository_slug:
    :return:
    """
    default_model_data = {
        "development": {"refId": None, "useDefault": True},
        "types": [
            {
                "displayName": "Bugfix",
                "enabled": True,
                "id": "BUGFIX",
                "prefix": "bugfix/",
            },
            {
                "displayName": "Feature",
                "enabled": True,
                "id": "FEATURE",
                "prefix": "feature/",
            },
            {
                "displayName": "Hotfix",
                "enabled": True,
                "id": "HOTFIX",
                "prefix": "hotfix/",
            },
            {
                "displayName": "Release",
                "enabled": True,
                "id": "RELEASE",
                "prefix": "release/",
            },
        ],
    }
    return self.set_branching_model(project_key, repository_slug, default_model_data)

enable_project_repo_hook_settings(project_key, hook_key)

Enable a repository hook for a given project :param project_key: The project key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
611
612
613
614
615
616
617
618
619
def enable_project_repo_hook_settings(self, project_key, hook_key):
    """
    Enable a repository hook for a given project
    :param project_key: The project key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}/enabled".format(self._url_project_repo_hook_settings(project_key), hook_key)
    return self.put(url)

enable_repo_hook_settings(project_key, repository_slug, hook_key)

Enable a repository hook for a given repo :param project_key: The project key :param repository_slug: The repository key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
def enable_repo_hook_settings(self, project_key, repository_slug, hook_key):
    """
    Enable a repository hook for a given repo
    :param project_key: The project key
    :param repository_slug: The repository key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}/enabled".format(
        self._url_repo_hook_settings(project_key, repository_slug),
        hook_key,
    )
    return self.put(url)

fork_repository(project_key, repository_slug, new_repository_slug)

Forks a repository within the same project. :param project_key: :param repository_slug: :param new_repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
896
897
898
899
900
901
902
903
904
905
906
907
908
909
def fork_repository(self, project_key, repository_slug, new_repository_slug):
    """
    Forks a repository within the same project.
    :param project_key:
    :param repository_slug:
    :param new_repository_slug:
    :return:
    """
    url = self._url_repo(project_key, repository_slug)
    body = {}
    if new_repository_slug is not None:
        body["name"] = new_repository_slug
        body["project"] = {"key": project_key}
    return self.post(url, data=body)

fork_repository_new_project(project_key, repository_slug, new_project_key, new_repository_slug)

Forks a repository to a separate project. :param project_key: Origin Project Key :param repository_slug: Origin repository slug :param new_project_key: Project Key of target project :param new_repository_slug: Target Repository slug :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
def fork_repository_new_project(
    self,
    project_key,
    repository_slug,
    new_project_key,
    new_repository_slug,
):
    """
    Forks a repository to a separate project.
    :param project_key: Origin Project Key
    :param repository_slug: Origin repository slug
    :param new_project_key: Project Key of target project
    :param new_repository_slug: Target Repository slug
    :return:
    """
    url = self._url_repo(project_key, repository_slug)
    body = {}
    if new_repository_slug is not None and new_project_key is not None:
        body["name"] = new_repository_slug
        body["project"] = {"key": new_project_key}
    return self.post(url, data=body)

get_announcement_banner()

Gets the announcement banner, if one exists and is available to the user :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
233
234
235
236
237
238
239
def get_announcement_banner(self):
    """
    Gets the announcement banner, if one exists and is available to the user
    :return:
    """
    url = self._url_announcement_banner()
    return self.get(url)

get_associated_build_statuses(commit)

To get the build statuses associated with a commit. :commit: str- commit id :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
218
219
220
221
222
223
224
225
226
227
228
def get_associated_build_statuses(self, commit):
    """
    To get the build statuses associated with a commit.
    :commit: str- commit id
    :return:
    """
    url = self.resource_url(
        "commits/{commitId}".format(commitId=commit),
        api_root="rest/build-status",
    )
    return self.get(url)

get_branch_permission(project_key, permission_id, repository_slug=None)

Returns a restriction as specified by a restriction id. The authenticated user must have REPO_ADMIN permission or higher to call this resource.

:param project_key: :param repository_slug: :param permission_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
def get_branch_permission(self, project_key, permission_id, repository_slug=None):
    """
    Returns a restriction as specified by a restriction id.
    The authenticated user must have REPO_ADMIN permission or higher to call this resource.

    :param project_key:
    :param repository_slug:
    :param permission_id:
    :return:
    """
    url = self._url_branches_permissions(project_key, permission_id, repository_slug)
    return self._get_paged(url)

get_branch_restrictions(workspace, repository_slug, kind=None, pattern=None, number=10)

Get all branch permissions.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_branch_restrictions(self, workspace, repository_slug, kind=None, pattern=None, number=10):
    """
    Get all branch permissions.
    """
    values = []
    for p in (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .branch_restrictions.each(kind=kind, pattern=pattern)
    ):
        values.append(p.data)
        if len(values) == number:
            break

    return values

get_branches(project_key, repository_slug, base=None, filter=None, start=0, limit=None, details=True, order_by='MODIFICATION', boost_matches=False)

Retrieve the branches matching the supplied filterText param. The authenticated user must have REPO_READ permission for the specified repository to call this resource. :param start: :param project_key: :param repository_slug: :param base: base branch/tag to compare each branch to (for the metadata providers that uses that information) :param filter: :param limit: OPTIONAL: The limit of the number of branches to return, this may be restricted by fixed system limits. Default by built-in method: None :param details: whether to retrieve plugin-provided metadata about each branch :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated) :param boost_matches: Controls whether exact and prefix matches will be boosted to the top :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
def get_branches(
    self,
    project_key,
    repository_slug,
    base=None,
    filter=None,
    start=0,
    limit=None,
    details=True,
    order_by="MODIFICATION",
    boost_matches=False,
):
    """
    Retrieve the branches matching the supplied filterText param.
    The authenticated user must have REPO_READ permission for the specified repository to call this resource.
    :param start:
    :param project_key:
    :param repository_slug:
    :param base: base branch/tag to compare each branch to (for the metadata providers that uses that information)
    :param filter:
    :param limit: OPTIONAL: The limit of the number of branches to return, this may be restricted by
                fixed system limits. Default by built-in method: None
    :param details: whether to retrieve plugin-provided metadata about each branch
    :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
    :param boost_matches: Controls whether exact and prefix matches will be boosted to the top
    :return:
    """
    url = self._url_repo_branches(project_key, repository_slug)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter:
        params["filterText"] = filter
    if base:
        params["base"] = base
    if order_by:
        params["orderBy"] = order_by
    params["details"] = details
    params["boostMatches"] = boost_matches
    return self._get_paged(url, params=params)

get_branches_permissions(project_key, permission_id, repository_slug=None, start=0, limit=25)

Get branches permissions from a given repo :param project_key: :param permission_id: :param repository_slug: :param start: :param limit: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
def get_branches_permissions(
    self,
    project_key,
    permission_id,
    repository_slug=None,
    start=0,
    limit=25,
):
    """
    Get branches permissions from a given repo
    :param project_key:
    :param permission_id:
    :param repository_slug:
    :param start:
    :param limit:
    :return:
    """
    url = self._url_branches_permissions(project_key, permission_id, repository_slug)
    params = {}
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start
    return self.get(url, params=params)

get_branching_model(project_key, repository_slug)

Get branching model :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2749
2750
2751
2752
2753
2754
2755
2756
2757
def get_branching_model(self, project_key, repository_slug):
    """
    Get branching model
    :param project_key:
    :param repository_slug:
    :return:
    """
    url = self._url_branching_model(project_key, repository_slug)
    return self.get(url)

get_categories(project_key, repository_slug=None)

Get a list of categories assigned to a project or repository. :param project_key: The project key as shown in URL. :param repository_slug: The repository as shown in URL (optional). :return: If 'repository_slug', returns the list with categories of the repository, otherwise, returns the list with the categories of the project 'project_key'

Source code in server/vendor/atlassian/bitbucket/__init__.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
def get_categories(self, project_key, repository_slug=None):
    """
    Get a list of categories assigned to a project or repository.
    :param project_key: The project key as shown in URL.
    :param repository_slug: The repository as shown in URL (optional).
    :return: If 'repository_slug', returns the list with categories of the repository,
    otherwise, returns the list with the categories of the project 'project_key'
    """
    url = "project/{}".format(project_key)
    if repository_slug:
        url = "{}/repository/{}".format(url, repository_slug)
    url = self.resource_url(url, api_root="rest/categories", api_version="latest")
    data = self.get(url)
    return data.get("result").get("categories")

get_changelog(project_key, repository_slug, ref_from, ref_to, start=0, limit=None)

Get change log between 2 refs :param start: :param project_key: :param repository_slug: :param ref_from: :param ref_to: :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by fixed system limits. Default by built-in method: None :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
def get_changelog(
    self,
    project_key,
    repository_slug,
    ref_from,
    ref_to,
    start=0,
    limit=None,
):
    """
    Get change log between 2 refs
    :param start:
    :param project_key:
    :param repository_slug:
    :param ref_from:
    :param ref_to:
    :param limit: OPTIONAL: The limit of the number of changes to return, this may be restricted by
            fixed system limits. Default by built-in method: None
    :return:
    """
    url = "{}/compare/commits".format(self._url_repo(project_key, repository_slug))
    params = {}
    if ref_from:
        params["from"] = ref_from
    if ref_to:
        params["to"] = ref_to
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

get_code_insights_report(project_key, repository_slug, commit_id, report_key)

Retrieve the specified code-insights report. :projectKey: str :repositorySlug: str :commit_id: str :report_key: str

Source code in server/vendor/atlassian/bitbucket/__init__.py
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
def get_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
    """
    Retrieve the specified code-insights report.
    :projectKey: str
    :repositorySlug: str
    :commit_id: str
    :report_key: str
    """
    url = self._url_code_insights_report(project_key, repository_slug, commit_id, report_key)
    return self.get(url)

get_commit_changes(project_key, repository_slug, hash_newest=None, merges='include', commit_id=None)

Get commit list from repo :param project_key: :param repository_slug: :param hash_newest: :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered. :param commit_id :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
def get_commit_changes(self, project_key, repository_slug, hash_newest=None, merges="include", commit_id=None):
    """
    Get commit list from repo
    :param project_key:
    :param repository_slug:
    :param hash_newest:
    :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered.
    :param commit_id
    :return:
    """
    url = self._url_commit_c(project_key, repository_slug, commit_id=commit_id)
    params = {"merges": merges}
    if hash_newest:
        params["until"] = hash_newest
    return self.get(url, params=params)

get_commit_info(project_key, repository_slug, commit, path=None)

Retrieve a single commit identified by its ID>. In general, that ID is a SHA1. From 2.11, ref names like "refs/heads/master" are no longer accepted by this resource. The authenticated user must have REPO_READ permission for the specified repository to call this resource. :param project_key: :param repository_slug: :param commit: the commit ID to retrieve :param path :OPTIONAL an optional path to filter the commit by. If supplied the details returned may not be for the specified commit. Instead, starting from the specified commit, they will be the details for the first commit affecting the specified path. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
def get_commit_info(self, project_key, repository_slug, commit, path=None):
    """
    Retrieve a single commit identified by its ID>. In general, that ID is a SHA1.
    From 2.11, ref names like "refs/heads/master" are no longer accepted by this resource.
    The authenticated user must have REPO_READ permission for the specified repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param commit: the commit ID to retrieve
    :param path :OPTIONAL an optional path to filter the commit by.
                    If supplied the details returned may not be for the specified commit.
                    Instead, starting from the specified commit, they will be the details for the first commit
                    affecting the specified path.
    :return:
    """

    url = self._url_commit(project_key, repository_slug, commit)
    params = {}
    if path:
        params["path"] = path
    return self.get(url, params=params)

get_commits(project_key, repository_slug, hash_oldest=None, hash_newest=None, follow_renames=False, ignore_missing=False, merges='include', with_counts=False, avatar_size=None, avatar_scheme=None, limit=None, until=None, since=None)

Get commit list from repo :param project_key: :param repository_slug: :param hash_oldest: :param hash_newest: :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered. :param follow_renames: OPTIONAL: if true, the commit history of the specified file will be followed past renames :param ignore_missing: OPTIONAL: true to ignore missing commits, false otherwise :param with_counts: OPTIONAL: optionally include the total number of commits and total number of unique authors :param avatar_size: OPTIONAL: if present the service adds avatar URLs for commit authors. :param avatar_scheme: OPTIONAL: the desired scheme for the avatar URL :param limit: OPTIONAL: The limit of the number of commits to return, this may be restricted by fixed system limits. Default by built-in method: None :param until: OPTIONAL: The commit ID or ref (inclusively) to retrieve commits before :param since: OPTIONAL: The commit ID or ref (exclusively) to retrieve commits after :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
def get_commits(
    self,
    project_key,
    repository_slug,
    hash_oldest=None,
    hash_newest=None,
    follow_renames=False,
    ignore_missing=False,
    merges="include",
    with_counts=False,
    avatar_size=None,
    avatar_scheme=None,
    limit=None,
    until=None,
    since=None,
):
    """
    Get commit list from repo
    :param project_key:
    :param repository_slug:
    :param hash_oldest:
    :param hash_newest:
    :param merges: OPTIONAL: include|exclude|only if present, controls how merge commits should be filtered.
    :param follow_renames: OPTIONAL: if true, the commit history of the specified file will be followed past renames
    :param ignore_missing: OPTIONAL: true to ignore missing commits, false otherwise
    :param with_counts: OPTIONAL: optionally include the total number of commits and total number of unique authors
    :param avatar_size: OPTIONAL: if present the service adds avatar URLs for commit authors.
    :param avatar_scheme: OPTIONAL: the desired scheme for the avatar URL
    :param limit: OPTIONAL: The limit of the number of commits to return, this may be restricted by
           fixed system limits. Default by built-in method: None
    :param until: OPTIONAL: The commit ID or ref (inclusively) to retrieve commits before
    :param since: OPTIONAL: The commit ID or ref (exclusively) to retrieve commits after
    :return:
    """
    url = self._url_commits(project_key, repository_slug)
    params = {"merges": merges}
    if hash_oldest:
        params["since"] = hash_oldest
    if hash_newest:
        params["until"] = hash_newest
    if follow_renames:
        params["followRenames"] = follow_renames
    if ignore_missing:
        params["ignoreMissing"] = ignore_missing
    if with_counts:
        params["withCounts"] = with_counts
    if avatar_size:
        params["avatarSize"] = avatar_size
    if avatar_scheme:
        params["avatarScheme"] = avatar_scheme
    if limit:
        params["limit"] = limit
    if self.cloud and (since or until):
        raise Exception("Not supported in Bitbucket Cloud")
    if since:
        params["since"] = since
    if until:
        params["until"] = until
    return self._get_paged(url, params=params)

get_content_of_file(project_key, repository_slug, filename, at=None, markup=None)

Retrieve the raw content for a file path at a specified revision. The authenticated user must have REPO_READ permission for the specified repository to call this resource. :param project_key: :param repository_slug: :param filename: :param at: OPTIONAL ref string :param markup: if present or "true", triggers the raw content to be markup-rendered and returned as HTML; otherwise, if not specified, or any value other than "true" the content is streamed without markup. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
def get_content_of_file(self, project_key, repository_slug, filename, at=None, markup=None):
    """
    Retrieve the raw content for a file path at a specified revision.
    The authenticated user must have REPO_READ permission for the specified repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param filename:
    :param at: OPTIONAL ref string
    :param markup: if present or "true", triggers the raw content to be markup-rendered and returned as HTML;
        otherwise, if not specified, or any value other than "true" the content is streamed without markup.
    :return:
    """
    url = "{}/raw/{}".format(self._url_repo(project_key, repository_slug), filename)
    params = {}
    if at is not None:
        params["at"] = at
    if markup is not None:
        params["markup"] = markup
    headers = self.form_token_headers
    return self.get(url, params=params, not_json_response=True, headers=headers)

get_current_license()

Retrieves details about the current license, as well as the current status of the system with regard to the installed license. The status includes the current number of users applied toward the license limit, as well as any status messages about the license (warnings about expiry or user counts exceeding license limits). The authenticated user must have ADMIN permission. Unauthenticated users, and non-administrators, are not permitted to access license details. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
152
153
154
155
156
157
158
159
160
161
162
163
def get_current_license(self):
    """
    Retrieves details about the current license, as well as the current status of the system with
    regard to the installed license. The status includes the current number of users applied
    toward the license limit, as well as any status messages about the license (warnings about expiry
    or user counts exceeding license limits).
    The authenticated user must have ADMIN permission. Unauthenticated users, and non-administrators,
    are not permitted to access license details.
    :return:
    """
    url = "{}/license".format(self._url_admin())
    return self.get(url)

get_dashboard_pull_requests(start=0, limit=None, closed_since=None, role=None, participant_status=None, state=None, order=None)

Get all pull requests where the current authenticated user is involved as either a reviewer, author or a participant :param start: :param limit: :param closed_since: OPTIONAL, defaults to returning pull requests regardless of closed since date. Permits returning only pull requests with a closed timestamp set more recently that (now - closedSince). Units are in seconds. So for example if closed since 86400 is set only pull requests closed in the previous 24 hours will be returned. :param role: OPTIONAL, defaults to returning pull requests for any role. If a role is supplied only pull requests where the authenticated user is a participant in the given role will be returned. Either REVIEWER, AUTHOR or PARTICIPANT. :param participant_status: OPTIONAL, defaults to returning pull requests with any participant status. A comma separated list of participant status. That is, one or more of UNAPPROVED, NEEDS_WORK, or APPROVED. :param state: OPTIONAL, defaults to returning pull requests in any state. If a state is supplied only pull requests in the specified state will be returned. Either OPEN, DECLINED or MERGED. Omit this parameter to return pull request in any state.

:param order: OPTIONAL, defaults to NEWEST, the order to return pull requests in, either OLDEST (as in: "oldest first"), NEWEST, PARTICIPANT_STATUS, or CLOSED_DATE. Where CLOSED_DATE is specified and the result set includes pull requests that are not in the closed state, these pull requests will appear first in the result set, followed by most recently closed pull requests. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
def get_dashboard_pull_requests(
    self,
    start=0,
    limit=None,
    closed_since=None,
    role=None,
    participant_status=None,
    state=None,
    order=None,
):
    """
    Get all pull requests where the current authenticated user is
    involved as either a reviewer, author or a participant
    :param start:
    :param limit:
    :param closed_since: OPTIONAL, defaults to returning pull
                         requests regardless of closed since date. Permits
                         returning only pull requests with a closed timestamp set more
                         recently that (now - closedSince). Units are in seconds. So
                         for example if closed since 86400 is set only pull requests
                         closed in the previous 24 hours will be returned.
    :param role: OPTIONAL, defaults to returning pull requests for
                 any role. If a role is supplied only pull requests where the
                 authenticated user is a participant in the given role will be
                 returned. Either REVIEWER, AUTHOR or PARTICIPANT.
    :param participant_status: OPTIONAL, defaults to returning
                               pull requests with any participant status. A comma separated
                               list of participant status. That is, one or more of
                               UNAPPROVED, NEEDS_WORK, or APPROVED.
    :param state: OPTIONAL, defaults to returning pull requests in
                  any state. If a state is supplied only pull requests in the
                  specified state will be returned. Either OPEN, DECLINED or
                  MERGED. Omit this parameter to return pull request in any
                  state.

    :param order: OPTIONAL, defaults to NEWEST, the order to
                  return pull requests in, either OLDEST (as in: "oldest
                  first"), NEWEST, PARTICIPANT_STATUS, or CLOSED_DATE. Where
                  CLOSED_DATE is specified and the result set includes pull
                  requests that are not in the closed state, these pull requests
                  will appear first in the result set, followed by most recently
                  closed pull requests.
    :return:
    """
    if self.cloud:
        raise Exception("Not supported in Bitbucket Cloud")
    url = self.resource_url("dashboard/pull-requests")
    params = {}
    if start:
        params["start"] = start
    if limit is not None:
        params["limit"] = limit
    if closed_since is not None:
        params["closedSince"] = closed_since
    if role is not None:
        params["role"] = role
    if participant_status is not None:
        params["participantStatus"] = participant_status
    if state is not None:
        params["state"] = state
    if order is not None:
        params["order"] = order
    return self._get_paged(url, params=params)

get_default_branch(project_key, repository_slug)

Get the default branch of the repository. The authenticated user must have REPO_READ permission for the specified repository to call this resource. :param project_key: The project key :param repository_slug: The repository key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
def get_default_branch(self, project_key, repository_slug):
    """
    Get the default branch of the repository.
    The authenticated user must have REPO_READ permission for the specified repository to call this resource.
    :param project_key: The project key
    :param repository_slug: The repository key
    :return:
    """
    url = self._url_repo_default_branche(project_key, repository_slug)
    return self.get(url)

get_default_reviewers(workspace, repository_slug, number=10)

Get all default reviewers for the repository.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_default_reviewers(self, workspace, repository_slug, number=10):
    """
    Get all default reviewers for the repository.
    """
    values = []
    for p in (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .default_reviewers.each()
    ):
        values.append(p.data)
        if len(values) == number:
            break

    return values

get_diff(project_key, repository_slug, path, hash_oldest, hash_newest)

Gets a diff of the changes available in the {@code from} commit but not in the {@code to} commit. If either the {@code from} or {@code to} commit are not specified, they will be replaced by the default branch of their containing repository. :param project_key: :param repository_slug: :param path: :param hash_oldest: the source commit (can be a partial/full commit ID or qualified/unqualified ref name) :param hash_newest: the target commit (can be a partial/full commit ID or qualified/unqualified ref name) :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
def get_diff(self, project_key, repository_slug, path, hash_oldest, hash_newest):
    """
    Gets a diff of the changes available in the {@code from} commit but not in the {@code to} commit.
    If either the {@code from} or {@code to} commit are not specified,
    they will be replaced by the default branch of their containing repository.
    :param project_key:
    :param repository_slug:
    :param path:
    :param hash_oldest: the source commit (can be a partial/full commit ID or qualified/unqualified ref name)
    :param hash_newest: the target commit (can be a partial/full commit ID or qualified/unqualified ref name)
    :return:
    """
    url = "{}/diff/{}".format(self._url_repo_compare(project_key, repository_slug), path)
    params = {}
    if hash_oldest:
        params["from"] = hash_oldest
    if hash_newest:
        params["to"] = hash_newest
    return (self.get(url, params=params) or {}).get("diffs")

get_file_list(project_key, repository_slug, sub_folder=None, query=None, start=0, limit=None)

Retrieve a page of files from particular directory of a repository. The search is done recursively, so all files from any subdirectory of the specified directory will be returned. The authenticated user must have REPO_READ permission for the specified repository to call this resource. :param start: :param project_key: :param repository_slug: :param sub_folder: a sub folder in the target repository to list the files from. :param query: the commit ID or ref (e.g. a branch or tag) to list the files at. If not specified the default branch will be used instead. :param limit: OPTIONAL :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
def get_file_list(
    self,
    project_key,
    repository_slug,
    sub_folder=None,
    query=None,
    start=0,
    limit=None,
):
    """
    Retrieve a page of files from particular directory of a repository.
    The search is done recursively, so all files from any subdirectory of the specified directory will be returned.
    The authenticated user must have REPO_READ permission for the specified repository to call this resource.
    :param start:
    :param project_key:
    :param repository_slug:
    :param sub_folder: a sub folder in the target repository to list the files from.
    :param query: the commit ID or ref (e.g. a branch or tag) to list the files at.
                  If not specified the default branch will be used instead.
    :param limit: OPTIONAL
    :return:
    """
    url = "{}/files".format(self._url_repo(project_key, repository_slug))
    if sub_folder:
        url = "{}/{}".format(url, sub_folder.lstrip("/"))
    params = {}
    if query:
        params["at"] = query
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

get_groups(group_filter=None, limit=25, start=0)

Get list of bitbucket groups. Use 'group_filter' for get specific group or get all group if necessary.

:param group_filter: str - groupname :param limit: int - paginated limit to retrieve :param start: int - paginated point to start retrieving :return: The collection as JSON with all relevant information about the group

Source code in server/vendor/atlassian/bitbucket/__init__.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_groups(self, group_filter=None, limit=25, start=0):
    """
    Get list of bitbucket groups.
    Use 'group_filter' for get specific group or get all group if necessary.

    :param group_filter: str - groupname
    :param limit: int - paginated limit to retrieve
    :param start: int - paginated point to start retrieving
    :return: The collection as JSON with all relevant information about the group
    """
    url = self.resource_url("groups", api_version="1.0")
    params = {}
    if group_filter:
        params["filter"] = group_filter
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start
    return self._get_paged(url, params=params)

get_issue(workspace, repository_slug, id)

Get the issue specified by id.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_issue(self, workspace, repository_slug, id):
    """
    Get the issue specified by ``id``.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .issues.get(id)
        .data
    )

get_issues(workspace, repository_slug, sort_by=None, query=None)

Get information about the issues tracked in the given repository. By default, the issues are sorted by ID in descending order. :param workspace: :param repository_slug: :param sort_by: optional key to sort available issues for :param query: optional query to filter available issues for. See https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering for an overview

:return: List of issues (direct, i.e. without the 'values' key)

Source code in server/vendor/atlassian/bitbucket/__init__.py
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_issues(self, workspace, repository_slug, sort_by=None, query=None):
    """
    Get information about the issues tracked in the given repository. By
    default, the issues are sorted by ID in descending order.
    :param workspace:
    :param repository_slug:
    :param sort_by: optional key to sort available issues for
    :param query: optional query to filter available issues for. See
      https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering
      for an overview

    :return: List of issues (direct, i.e. without the 'values' key)
    """
    values = []
    for p in (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .issues.each(q=query, sort=sort_by)
    ):
        values.append(p.data)

    return values

get_mail_configuration()

Retrieves the current mail configuration. The authenticated user must have the SYS_ADMIN permission to call this resource. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
168
169
170
171
172
173
174
175
def get_mail_configuration(self):
    """
    Retrieves the current mail configuration.
    The authenticated user must have the SYS_ADMIN permission to call this resource.
    :return:
    """
    url = self._url_mail_server()
    return self.get(url)

get_mail_sender_address()

Retrieves the server email address :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
180
181
182
183
184
185
186
def get_mail_sender_address(self):
    """
    Retrieves the server email address
    :return:
    """
    url = self._url_mail_server_sender_address()
    return self.get(url)

get_pipeline(workspace, repository_slug, uuid)

Get information about the pipeline specified by uuid. :param workspace: :param repository_slug: :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)

Source code in server/vendor/atlassian/bitbucket/__init__.py
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_pipeline(self, workspace, repository_slug, uuid):
    """
    Get information about the pipeline specified by ``uuid``.
    :param workspace:
    :param repository_slug:
    :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.get(uuid)
        .data
    )

get_pipeline_step(workspace, repository_slug, pipeline_uuid, step_uuid)

Get information about a step of a pipeline, specified by respective UUIDs. :param workspace: :param repository_slug: :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number) :param step_uuid: Step identifier (with surrounding {})

Source code in server/vendor/atlassian/bitbucket/__init__.py
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_pipeline_step(self, workspace, repository_slug, pipeline_uuid, step_uuid):
    """
    Get information about a step of a pipeline, specified by respective UUIDs.
    :param workspace:
    :param repository_slug:
    :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number)
    :param step_uuid: Step identifier (with surrounding {})
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.get(pipeline_uuid)
        .step(step_uuid)
        .data
    )

get_pipeline_step_log(workspace, repository_slug, pipeline_uuid, step_uuid)

Get log of a step of a pipeline, specified by respective UUIDs. :param workspace: :param repository_slug: :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number) :param step_uuid: Step identifier (with surrounding {}) :return: byte string log

Source code in server/vendor/atlassian/bitbucket/__init__.py
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_pipeline_step_log(self, workspace, repository_slug, pipeline_uuid, step_uuid):
    """
    Get log of a step of a pipeline, specified by respective UUIDs.
    :param workspace:
    :param repository_slug:
    :param pipeline_uuid: Pipeline identifier (with surrounding {}; NOT the build number)
    :param step_uuid: Step identifier (with surrounding {})
    :return: byte string log
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.get(pipeline_uuid)
        .step(step_uuid)
        .log()
    )

get_pipeline_steps(workspace, repository_slug, uuid)

Get information about the steps of the pipeline specified by uuid. :param workspace: :param repository_slug: :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)

Source code in server/vendor/atlassian/bitbucket/__init__.py
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_pipeline_steps(self, workspace, repository_slug, uuid):
    """
    Get information about the steps of the pipeline specified by ``uuid``.
    :param workspace:
    :param repository_slug:
    :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)
    """
    values = []
    for s in (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.get(uuid)
        .steps()
    ):
        values.append(s.data)

    return values

get_pipelines(workspace, repository_slug, number=10, sort_by='-created_on')

Get information about latest pipelines runs.

:param workspace: :param repository_slug: :param sort_by: :param number: number of pipelines to fetch :param :sort_by: optional key to sort available pipelines for :return: List of pipeline data

Source code in server/vendor/atlassian/bitbucket/__init__.py
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_pipelines(self, workspace, repository_slug, number=10, sort_by="-created_on"):
    """
    Get information about latest pipelines runs.

    :param workspace:
    :param repository_slug:
    :param sort_by:
    :param number: number of pipelines to fetch
    :param :sort_by: optional key to sort available pipelines for
    :return: List of pipeline data
    """
    values = []
    for p in (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.each(sort=sort_by)
    ):
        values.append(p.data)
        if len(values) == number:
            break

    return values

get_project_audit_log(project_key, start=0, limit=None)

Get the audit log of the project :param start: :param limit: :param project_key: The project key :return: List of events of the audit log

Source code in server/vendor/atlassian/bitbucket/__init__.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
def get_project_audit_log(self, project_key, start=0, limit=None):
    """
    Get the audit log of the project
    :param start:
    :param limit:
    :param project_key: The project key
    :return: List of events of the audit log
    """
    url = self._url_project_audit_log(project_key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

get_project_condition(project_key, id_condition)

Request type: GET Return a specific condition with reviewers list that has been configured for this project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264901504 :projectKey: str - project key involved :idCondition: int - condition id involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
664
665
666
667
668
669
670
671
672
673
674
675
def get_project_condition(self, project_key, id_condition):
    """
    Request type: GET
    Return a specific condition with reviewers list that has been configured for this project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264901504
    :projectKey: str - project key involved
    :idCondition: int - condition id involved
    :return:
    """
    url = self._url_project_condition(project_key, id_condition)
    return self.get(url) or {}

get_project_conditions(project_key)

Request type: GET Return a page of defaults conditions with reviewers list that have been configured for this project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264904368 :projectKey: str :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
640
641
642
643
644
645
646
647
648
649
650
def get_project_conditions(self, project_key):
    """
    Request type: GET
    Return a page of defaults conditions with reviewers list that have been configured for this project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264904368
    :projectKey: str
    :return:
    """
    url = self._url_project_conditions(project_key)
    return self.get(url) or {}

get_project_repo_hook_settings(project_key, hook_key)

Get a repository hook from a given project :param project_key: The project key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
601
602
603
604
605
606
607
608
609
def get_project_repo_hook_settings(self, project_key, hook_key):
    """
    Get a repository hook from a given project
    :param project_key: The project key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}".format(self._url_project_repo_hook_settings(project_key), hook_key)
    return self.get(url)

get_project_tags(project_key, repository_slug, tag_name=None)

Retrieve a tag in the specified repository. The authenticated user must have REPO_READ permission for the context repository to call this resource. Search uri is api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*} :param project_key: :param repository_slug: :param tag_name: OPTIONAL: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
def get_project_tags(self, project_key, repository_slug, tag_name=None):
    """
    Retrieve a tag in the specified repository.
    The authenticated user must have REPO_READ permission for the context repository to call this resource.
    Search uri is api/1.0/projects/{projectKey}/repos/{repositorySlug}/tags/{name:.*}
    :param project_key:
    :param repository_slug:
    :param tag_name: OPTIONAL:
    :return:
    """
    url = self._url_repo_tags(project_key, repository_slug)
    if tag_name is not None:
        return self.get("{}/{}".format(url, tag_name))

    return self._get_paged(url)

get_pull_request(project_key, repository_slug, pull_request_id)

Retrieve a pull request. The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource. :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
def get_pull_request(self, project_key, repository_slug, pull_request_id):
    """
    Retrieve a pull request.
    The authenticated user must have REPO_READ permission
    for the repository that this pull request targets to call this resource.
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :return:
    """
    url = self._url_pull_request(project_key, repository_slug, pull_request_id)
    return self.get(url)

get_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)

Retrieves a pull request comment. The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource. :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :param comment_id: the ID of the comment to retrieve :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
def get_pull_request_comment(self, project_key, repository_slug, pull_request_id, comment_id):
    """
    Retrieves a pull request comment.
    The authenticated user must have REPO_READ permission
    for the repository that this pull request targets to call this resource.
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :param comment_id: the ID of the comment to retrieve
    :return:
    """
    url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
    return self.get(url)

get_pull_request_settings(project_key, repository_slug)

Get pull request settings. :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1551
1552
1553
1554
1555
1556
1557
1558
1559
def get_pull_request_settings(self, project_key, repository_slug):
    """
    Get pull request settings.
    :param project_key:
    :param repository_slug:
    :return:
    """
    url = self._url_pull_request_settings(project_key, repository_slug)
    return self.get(url)

get_pull_requests(project_key, repository_slug, state='OPEN', order='newest', limit=100, start=0, at=None)

Get pull requests :param project_key: :param repository_slug: :param state: :param order: OPTIONAL: defaults to NEWEST the order to return pull requests in, either OLDEST (as in: "oldest first") or NEWEST. :param limit: :param start: :param at: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
def get_pull_requests(
    self,
    project_key,
    repository_slug,
    state="OPEN",
    order="newest",
    limit=100,
    start=0,
    at=None,
):
    """
    Get pull requests
    :param project_key:
    :param repository_slug:
    :param state:
    :param order: OPTIONAL: defaults to NEWEST the order to return pull requests in, either OLDEST
                            (as in: "oldest first") or NEWEST.
    :param limit:
    :param start:
    :param at:
    :return:
    """
    url = self._url_pull_requests(project_key, repository_slug)
    params = {}
    if state:
        params["state"] = state
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start
    if order:
        params["order"] = order
    if at:
        params["at"] = at
    return self._get_paged(url, params=params)

get_pull_requests_activities(project_key, repository_slug, pull_request_id, start=0, limit=None)

Get pull requests activities :param limit: :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :param start: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
def get_pull_requests_activities(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    start=0,
    limit=None,
):
    """
    Get pull requests activities
    :param limit:
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :param start:
    :return:
    """
    if self.cloud:
        url = "{}/activity".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
    else:
        url = "{}/activities".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

get_pull_requests_changes(project_key, repository_slug, pull_request_id, start=0, limit=None)

Get pull requests changes :param start: :param limit: :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
def get_pull_requests_changes(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    start=0,
    limit=None,
):
    """
    Get pull requests changes
    :param start:
    :param limit:
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :return:
    """
    url = "{}/changes".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

get_pull_requests_commits(project_key, repository_slug, pull_request_id, start=0, limit=None)

Get pull requests commits :param start: :param limit: :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :start :limit :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
def get_pull_requests_commits(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    start=0,
    limit=None,
):
    """
    Get pull requests commits
    :param start:
    :param limit:
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :start
    :limit
    :return:
    """
    url = "{}/commits".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

get_pull_requests_participants(project_key, repository_slug, pull_request_id, start=0, limit=None)

Get all participants of a pull request :param start: :param limit: :param project_key: :param repository_slug: :param pull_request_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
def get_pull_requests_participants(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    start=0,
    limit=None,
):
    """
    Get all participants of a pull request
    :param start:
    :param limit:
    :param project_key:
    :param repository_slug:
    :param pull_request_id:
    :return:
    """
    url = self._url_pull_request_participants(project_key, repository_slug, pull_request_id)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params)

get_pullrequest(*args, **kwargs)

Deprecated name since 1.15.1. Let's use the get_pull_request()

Source code in server/vendor/atlassian/bitbucket/__init__.py
1746
1747
1748
1749
1750
@deprecated(version="1.15.1", reason="Use get_pull_request()")
def get_pullrequest(self, *args, **kwargs):
    """
    Deprecated name since 1.15.1. Let's use the get_pull_request()
    """

get_repo(project_key, repository_slug)

Get a specific repository from a project. This operates based on slug not name which may be confusing to some users. :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :return: Dictionary of request response

Source code in server/vendor/atlassian/bitbucket/__init__.py
847
848
849
850
851
852
853
854
855
856
def get_repo(self, project_key, repository_slug):
    """
    Get a specific repository from a project. This operates based on slug not name which may
    be confusing to some users.
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :return: Dictionary of request response
    """
    url = self._url_repo(project_key, repository_slug)
    return self.get(url)

get_repo_audit_log(project_key, repository_slug, start=0, limit=None)

Get the audit log of the repository :param start: :param limit: :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :return: List of events of the audit log

Source code in server/vendor/atlassian/bitbucket/__init__.py
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
def get_repo_audit_log(self, project_key, repository_slug, start=0, limit=None):
    """
    Get the audit log of the repository
    :param start:
    :param limit:
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :return: List of events of the audit log
    """
    url = self._url_repo_audit_log(project_key, repository_slug)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

get_repo_condition(project_key, repo_key, id_condition)

Request type: GET Return a specific condition with reviewers list that have been configured for this repository slug inside project specified. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632 :projectKey: str- project key involved :repoKey: str - repo key involved :idCondition: int - condition id involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
def get_repo_condition(self, project_key, repo_key, id_condition):
    """
    Request type: GET
    Return a specific condition with reviewers list
        that have been configured for this repository slug inside project specified.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :idCondition: int - condition id involved
    :return:
    """
    url = self._url_repo_condition(project_key, repo_key, id_condition)
    return self.get(url) or {}

get_repo_conditions(project_key, repo_key)

Request type: GET Return a page of defaults conditions with reviewers list (type REPOSITORY or PROJECT) that have been configured for this repository slug inside project specified. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992 :projectKey: str- project key involved :repoKey: str - repo key involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
def get_repo_conditions(self, project_key, repo_key):
    """
    Request type: GET
    Return a page of defaults conditions with reviewers list (type REPOSITORY or PROJECT)
    that have been configured for this repository slug inside project specified.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :return:
    """
    url = self._url_repo_conditions(project_key, repo_key)
    return self.get(url) or {}

get_repo_hook_settings(project_key, repository_slug, hook_key)

Get a repository hook from a given repo :param project_key: The project key :param repository_slug: The repository key :param hook_key: The repository hook key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
def get_repo_hook_settings(self, project_key, repository_slug, hook_key):
    """
    Get a repository hook from a given repo
    :param project_key: The project key
    :param repository_slug: The repository key
    :param hook_key: The repository hook key
    :return:
    """
    url = "{}/{}".format(
        self._url_repo_hook_settings(project_key, repository_slug),
        hook_key,
    )
    return self.get(url)

get_repo_labels(project_key, repository_slug)

Get labels for a specific repository from a project. This operates based on slug not name which may be confusing to some users. (BitBucket Server only) :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :return: Dictionary of request response

Source code in server/vendor/atlassian/bitbucket/__init__.py
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
def get_repo_labels(self, project_key, repository_slug):
    """
    Get labels for a specific repository from a project. This operates based on slug not name which may
    be confusing to some users. (BitBucket Server only)
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :return: Dictionary of request response
    """
    url = self._url_repo_labels(project_key, repository_slug)
    return self.get(url)

get_repo_project_conditions(project_key, repo_key)

Request type: GET Return a page of repository conditions (only type PROJECT) with reviewers list associated that have been configured for this repository slug inside project specified. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992 :projectKey: str- project key involved :repoKey: str - repo key involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
def get_repo_project_conditions(self, project_key, repo_key):
    """
    Request type: GET
    Return a page of repository conditions (only type PROJECT) with reviewers list associated
    that have been configured for this repository slug inside project specified.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :return:
    """
    response = self.get_repo_conditions(project_key, repo_key)
    count = 0
    for condition in response:
        if condition["scope"]["type"] == "REPOSITORY":
            del response[count]
        count += 1
    return response

get_repo_repo_conditions(project_key, repo_key)

Request type: GET Return a page of repository conditions (only type REPOSITORY) with reviewers list associated that have been configured for this repository slug inside project specified. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992 :projectKey: str- project key involved :repoKey: str - repo key involved :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
def get_repo_repo_conditions(self, project_key, repo_key):
    """
    Request type: GET
    Return a page of repository conditions (only type REPOSITORY) with reviewers list associated
    that have been configured for this repository slug inside project specified.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264928992
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :return:
    """
    response = self.get_repo_conditions(project_key, repo_key)
    count = 0
    for condition in response:
        if condition["scope"]["type"] == "PROJECT":
            del response[count]
        count += 1
    return response

get_repositories(workspace, role=None, query=None, sort=None)

Get all repositories in a workspace.

:param workspace: :param role: Filters the result based on the authenticated user's role on each repository. One of: member, contributor, admin, owner :param query: Query string to narrow down the response. :param sort: Field by which the results should be sorted.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def get_repositories(self, workspace, role=None, query=None, sort=None):
    """
    Get all repositories in a workspace.

    :param workspace:
    :param role: Filters the result based on the authenticated user's role on each repository.
                  One of: member, contributor, admin, owner
    :param query: Query string to narrow down the response.
    :param sort: Field by which the results should be sorted.
    """
    return [
        r.data
        for r in Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.each(role=role, q=query, sort=sort)
    ]

get_required_reviewers_for_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, dest_branch)

Get required reviewers for PR creation :param source_project: the project that the PR source is from :param source_repo: the repository that the PR source is from :param source_branch: the branch name of the PR :param dest_project: the project that the PR destination is from :param dest_repo: the repository that the PR destination is from :param dest_branch: where the PR is being merged into :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
def get_required_reviewers_for_pull_request(
    self, source_project, source_repo, dest_project, dest_repo, source_branch, dest_branch
):
    """
    Get required reviewers for PR creation
    :param source_project: the project that the PR source is from
    :param source_repo: the repository that the PR source is from
    :param source_branch: the branch name of the PR
    :param dest_project: the project that the PR destination is from
    :param dest_repo: the repository that the PR destination is from
    :param dest_branch: where the PR is being merged into
    :return:
    """
    url = "{}/reviewers".format(
        self._url_repo(
            dest_project,
            dest_repo,
            api_root="rest/default-reviewers",
            api_version="1.0",
        )
    )
    source_repo_id = self.get_repo(source_project, source_repo)["id"]
    dest_repo_id = self.get_repo(dest_project, dest_repo)["id"]
    params = {
        "sourceRepoId": source_repo_id,
        "sourceRefId": source_branch,
        "targetRepoId": dest_repo_id,
        "targetRefId": dest_branch,
    }
    return self.get(url, params=params)

get_ssh_settings()

Retrieve ssh settings for user :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
197
198
199
200
201
202
203
def get_ssh_settings(self):
    """
    Retrieve ssh settings for user
    :return:
    """
    url = self.resource_url("settings", api_root="rest/ssh")
    return self.get(url)

get_tags(project_key, repository_slug, filter='', limit=1000, order_by=None, start=0)

Retrieve the tags matching the supplied filterText param. The authenticated user must have REPO_READ permission for the context repository to call this resource. :param project_key: :param repository_slug: :param filter: :param start: :param limit: OPTIONAL: The limit of the number of tags to return, this may be restricted by fixed system limits. Default by built-in method: 1000 :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated) :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
def get_tags(
    self,
    project_key,
    repository_slug,
    filter="",
    limit=1000,
    order_by=None,
    start=0,
):
    """
    Retrieve the tags matching the supplied filterText param.
    The authenticated user must have REPO_READ permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param filter:
    :param start:
    :param limit: OPTIONAL: The limit of the number of tags to return, this may be restricted by
            fixed system limits. Default by built-in method: 1000
    :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
    :return:
    """
    url = self._url_repo_tags(project_key, repository_slug)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter:
        params["filterText"] = filter
    if order_by:
        params["orderBy"] = order_by
    return self._get_paged(url, params=params)

get_task(task_id)

Get task information by ID :param task_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2146
2147
2148
2149
2150
2151
2152
2153
def get_task(self, task_id):
    """
    Get task information by ID
    :param task_id:
    :return:
    """
    url = self._url_task(task_id)
    return self.get(url)

get_tasks(project_key, repository_slug, pull_request_id)

Get all tasks for the pull request :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
def get_tasks(self, project_key, repository_slug, pull_request_id):
    """
    Get all tasks for the pull request
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :return:
    """
    if self.cloud:
        raise Exception("Not supported in Bitbucket Cloud")
    url = "{}/tasks".format(self._url_pull_request(project_key, repository_slug, pull_request_id))
    return self.get(url)

get_users(user_filter=None, limit=25, start=0)

Get list of bitbucket users. Use 'user_filter' for get specific users or get all users if necessary. :param user_filter: str - username, displayname or email :param limit: int - paginated limit to retrieve :param start: int - paginated point to start retreiving :return: The collection as JSON with all relevant information about the licensed user

Source code in server/vendor/atlassian/bitbucket/__init__.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def get_users(self, user_filter=None, limit=25, start=0):
    """
    Get list of bitbucket users.
    Use 'user_filter' for get specific users or get all users if necessary.
    :param user_filter: str - username, displayname or email
    :param limit: int - paginated limit to retrieve
    :param start: int - paginated point to start retreiving
    :return: The collection as JSON with all relevant information about the licensed user
    """
    url = self.resource_url("users", api_version="1.0")
    params = {}
    if user_filter:
        params["filter"] = user_filter
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start
    return self.get(url, params=params)

get_users_info(user_filter=None, start=0, limit=25)

The authenticated user must have the LICENSED_USER permission to call this resource. :param user_filter: if specified only users with usernames, display name or email addresses containing the supplied string will be returned :param limit: :param start: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
def get_users_info(self, user_filter=None, start=0, limit=25):
    """
    The authenticated user must have the LICENSED_USER permission to call this resource.
    :param user_filter: if specified only users with usernames, display name or email addresses
        containing the supplied string will be returned
    :param limit:
    :param start:
    :return:
    """
    url = "{}/users".format(self._url_admin(api_version="1.0"))
    params = {}
    if limit:
        params["limit"] = limit
    if start:
        params["start"] = start
    if user_filter:
        params["filter"] = user_filter
    return self._get_paged(url, params=params)

get_webhook(project_key, repository_slug, webhook_id)

Retrieve a webhook. The authenticated user must have REPO_ADMIN permission for the context repository to call this resource. :param project_key: :param repository_slug: :param webhook_id: the ID of the webhook within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
def get_webhook(self, project_key, repository_slug, webhook_id):
    """
    Retrieve a webhook.
    The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param webhook_id: the ID of the webhook within the repository
    :return:
    """
    url = self._url_webhook(project_key, repository_slug, webhook_id)
    return self.get(url)

get_webhooks(project_key, repository_slug, event=None, statistics=False)

Get webhooks :param project_key: :param repository_slug: :param event: OPTIONAL: defaults to None :param statistics: OPTIONAL: defaults to False :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
def get_webhooks(
    self,
    project_key,
    repository_slug,
    event=None,
    statistics=False,
):
    """
    Get webhooks
    :param project_key:
    :param repository_slug:
    :param event: OPTIONAL: defaults to None
    :param statistics: OPTIONAL: defaults to False
    :return:
    """
    url = self._url_webhooks(project_key, repository_slug)
    params = {}
    if event:
        params["event"] = event
    if statistics:
        params["statistics"] = statistics
    return self._get_paged(url, params=params)

group_members(group, start=0, limit=None)

Get group of members :param group: The group name to query :param start: :param limit: :return: A list of group members

Source code in server/vendor/atlassian/bitbucket/__init__.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def group_members(self, group, start=0, limit=None):
    """
    Get group of members
    :param group: The group name to query
    :param start:
    :param limit:
    :return: A list of group members
    """

    url = "{}/groups/more-members".format(self._url_admin())
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if group:
        params["context"] = group
    return self._get_paged(url, params=params)

health_check()

Get health status https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
205
206
207
208
209
210
211
212
213
214
215
216
def health_check(self):
    """
    Get health status
    https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html
    :return:
    """
    # check as Troubleshooting & Support Tools Plugin
    response = self.get("rest/troubleshooting/1.0/check/")
    if not response:
        # check as support tools
        response = self.get("rest/supportHealthCheck/1.0/check/")
    return response

is_default_reviewer(workspace, repository_slug, user)

Check if the user is a default reviewer of the repository.

:param workspace: :param repository_slug: :param user: The username or account UUID to check. :return: True if present, False if not.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def is_default_reviewer(self, workspace, repository_slug, user):
    """
    Check if the user is a default reviewer of the repository.

    :param workspace:
    :param repository_slug:
    :param user: The username or account UUID to check.
    :return: True if present, False if not.
    """
    if (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .default_reviewers.get(user)
        is None
    ):
        return False

    return True

is_pull_request_can_be_merged(project_key, repository_slug, pr_id)

Test whether a pull request can be merged. A pull request may not be merged if: - there are conflicts that need to be manually resolved before merging; and/or - one or more merge checks have vetoed the merge. The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource.

:param project_key: PROJECT :param repository_slug: my_shiny_repo :param pr_id: 2341 :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
def is_pull_request_can_be_merged(self, project_key, repository_slug, pr_id):
    """
    Test whether a pull request can be merged.
    A pull request may not be merged if:
    - there are conflicts that need to be manually resolved before merging; and/or
    - one or more merge checks have vetoed the merge.
    The authenticated user must have REPO_READ permission for the repository
    that this pull request targets to call this resource.

    :param project_key: PROJECT
    :param repository_slug: my_shiny_repo
    :param pr_id: 2341
    :return:
    """
    url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id))
    return self.get(url)

markup_preview(data)

Preview generated HTML for the given markdown content. Only authenticated users may call this resource. :param data: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
24
25
26
27
28
29
30
31
32
33
def markup_preview(self, data):
    """
    Preview generated HTML for the given markdown content.
    Only authenticated users may call this resource.
    :param data:
    :return:
    """

    url = self.resource_url("markup/preview")
    return self.post(url, data=data)

merge_pull_request(project_key, repository_slug, pr_id, pr_version)

Merge pull request The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource.

:param project_key: PROJECT :param repository_slug: my_shiny_repo :param pr_id: 2341 :param pr_version: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
def merge_pull_request(self, project_key, repository_slug, pr_id, pr_version):
    """
    Merge pull request
    The authenticated user must have REPO_READ permission for the repository
    that this pull request targets to call this resource.

    :param project_key: PROJECT
    :param repository_slug: my_shiny_repo
    :param pr_id: 2341
    :param pr_version:
    :return:
    """
    url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id))
    params = {}
    if not self.cloud:
        params["version"] = pr_version
    return self.post(url, params=params)

open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description, reviewers=None, include_required_reviewers=False)

Create a new pull request between two branches. The branches may be in the same repository_slug, or different ones. When using different repositories, they must still be in the same {@link Repository#getHierarchyId() hierarchy}. The authenticated user must have REPO_READ permission for the "from" and "to"repositories to call this resource. :param source_project: the project that the PR source is from :param source_repo: the repository that the PR source is from :param dest_project: the project that the PR destination is from :param dest_repo: the repository that the PR destination is from :param source_branch: the branch name of the PR :param destination_branch: where the PR is being merged into :param title: the title of the PR :param description: the description of what the PR does :param reviewers: the list of reviewers or a single reviewer of the PR :param include_required_reviewers: OPTIONAL defaults to False, include required reviewers for the PR :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
def open_pull_request(
    self,
    source_project,
    source_repo,
    dest_project,
    dest_repo,
    source_branch,
    destination_branch,
    title,
    description,
    reviewers=None,
    include_required_reviewers=False,
):
    """
    Create a new pull request between two branches.
    The branches may be in the same repository_slug, or different ones.
    When using different repositories, they must still be in the same {@link Repository#getHierarchyId() hierarchy}.
    The authenticated user must have REPO_READ permission for the "from" and "to"repositories to call this resource.
    :param source_project: the project that the PR source is from
    :param source_repo: the repository that the PR source is from
    :param dest_project: the project that the PR destination is from
    :param dest_repo: the repository that the PR destination is from
    :param source_branch: the branch name of the PR
    :param destination_branch: where the PR is being merged into
    :param title: the title of the PR
    :param description: the description of what the PR does
    :param reviewers: the list of reviewers or a single reviewer of the PR
    :param include_required_reviewers: OPTIONAL defaults to False, include required reviewers for the PR
    :return:
    """
    body = {
        "title": title,
        "description": description,
        "fromRef": {
            "id": source_branch,
            "repository": {
                "slug": source_repo,
                "name": source_repo,
                "project": {"key": source_project},
            },
        },
        "toRef": {
            "id": destination_branch,
            "repository": {
                "slug": dest_repo,
                "name": dest_repo,
                "project": {"key": dest_project},
            },
        },
        "reviewers": [],
    }

    def add_reviewer(reviewer_name):
        entry = {"user": {"name": reviewer_name}}
        body["reviewers"].append(entry)

    if not self.cloud and include_required_reviewers:
        required_reviewers = self.get_required_reviewers_for_pull_request(
            source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch
        )
        for required_reviewer in required_reviewers:
            add_reviewer(required_reviewer["name"])

    if reviewers is not None:
        if isinstance(reviewers, str):
            add_reviewer(reviewers)
        elif isinstance(reviewers, list):
            for reviewer in reviewers:
                add_reviewer(reviewer)

    return self.create_pull_request(dest_project, dest_repo, body)

project(key)

Provide project info :param key: The project key :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
336
337
338
339
340
341
342
343
def project(self, key):
    """
    Provide project info
    :param key: The project key
    :return:
    """
    url = self._url_project(key)
    return self.get(url) or {}

project_avatar(key, content_type='image/png')

Get project avatar :param key: The project key :param content_type: The content type to get

:return: Value of get request

Source code in server/vendor/atlassian/bitbucket/__init__.py
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def project_avatar(self, key, content_type="image/png"):
    """
    Get project avatar
    :param key: The project key
    :param content_type: The content type to get

    :return: Value of get request
    """
    url = self._url_project_avatar(key)
    headers = dict(self.default_headers)
    headers["Accept"] = content_type
    headers["X-Atlassian-Token"] = "no-check"

    return self.get(url, not_json_response=True, headers=headers)

project_default_permissions(project_key, permission)

Check if the specified permission is the default permission for a given project :param project_key: The project key :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
547
548
549
550
551
552
553
554
555
def project_default_permissions(self, project_key, permission):
    """
    Check if the specified permission is the default permission for a given project
    :param project_key: The project key
    :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
    :return:
    """
    url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
    return self.get(url)

project_exists(project_key)

Check if project with the provided project key exists and available. :param project_key: Key of the project where to check for repository. :return: False is requested repository doesn't exist in the project or not accessible to the requestor

Source code in server/vendor/atlassian/bitbucket/__init__.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
def project_exists(self, project_key):
    """
    Check if project with the provided project key exists and available.
    :param project_key: Key of the project where to check for repository.
    :return: False is requested repository doesn't exist in the project or not accessible to the requestor
    """
    exists = False
    try:
        self.project(project_key)
        exists = True
    except HTTPError as e:
        if e.response.status_code in (401, 404):
            pass
    return exists

project_grant_default_permissions(project_key, permission)

Grant the specified project permission to all users for a given project :param project_key: The project key :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
557
558
559
560
561
562
563
564
565
def project_grant_default_permissions(self, project_key, permission):
    """
    Grant the specified project permission to all users for a given project
    :param project_key: The project key
    :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
    :return:
    """
    url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
    return self.post(url, params={"allow": True})

project_grant_group_permissions(project_key, group_name, permission)

Grant the specified project permission to a specific group :param project_key: The project key :param group_name: group to be granted :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
520
521
522
523
524
525
526
527
528
529
530
def project_grant_group_permissions(self, project_key, group_name, permission):
    """
    Grant the specified project permission to a specific group
    :param project_key: The project key
    :param group_name: group to be granted
    :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
    :return:
    """
    url = self._url_project_groups(project_key)
    params = {"permission": permission, "name": group_name}
    return self.put(url, params=params)

project_grant_user_permissions(project_key, username, permission)

Grant the specified project permission to a specific user :param project_key: The project key :param username: username to be granted :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
471
472
473
474
475
476
477
478
479
480
481
def project_grant_user_permissions(self, project_key, username, permission):
    """
    Grant the specified project permission to a specific user
    :param project_key: The project key
    :param username: username to be granted
    :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
    :return:
    """
    url = self._url_project_users(project_key)
    params = {"permission": permission, "name": username}
    return self.put(url, params=params)

project_groups(key, start=0, limit=None, filter_str=None)

Get Project Groups :param limit: :param limit: :param start: :param key: The project key :param filter_str: OPTIONAL: group filter string :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
def project_groups(self, key, start=0, limit=None, filter_str=None):
    """
    Get Project Groups
    :param limit:
    :param limit:
    :param start:
    :param key: The project key
    :param filter_str: OPTIONAL: group filter string
    :return:
    """
    url = self._url_project_groups(key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

project_groups_with_administrator_permissions(key)

Get groups with admin permissions :param key: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1028
1029
1030
1031
1032
1033
1034
def project_groups_with_administrator_permissions(self, key):
    """
    Get groups with admin permissions
    :param key:
    :return:
    """
    return [group["group"]["name"] for group in self.project_groups(key) if group["permission"] == "PROJECT_ADMIN"]

project_keys(key, start=0, limit=None, filter_str=None)

Get SSH access keys added to the project :param start: :param limit: :param key: The project key :param filter_str: OPTIONAL: users filter string :return: The list of SSH access keys

Source code in server/vendor/atlassian/bitbucket/__init__.py
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
def project_keys(self, key, start=0, limit=None, filter_str=None):
    """
    Get SSH access keys added to the project
    :param start:
    :param limit:
    :param key: The project key
    :param filter_str:  OPTIONAL: users filter string
    :return: The list of SSH access keys
    """
    url = "{}/ssh".format(self._url_project(key, api_root="rest/keys"))
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

project_list(start=0, limit=None)

Provide the project list

:return: A list of projects

Source code in server/vendor/atlassian/bitbucket/__init__.py
302
303
304
305
306
307
308
309
310
311
312
313
314
def project_list(self, start=0, limit=None):
    """
    Provide the project list

    :return: A list of projects
    """
    url = self._url_projects()
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

project_remove_default_permissions(project_key, permission)

Revoke the specified project permission for all users for a given project :param project_key: The project key :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
567
568
569
570
571
572
573
574
575
def project_remove_default_permissions(self, project_key, permission):
    """
    Revoke the specified project permission for all users for a given project
    :param project_key: The project key
    :param permission: the project permissions available are 'PROJECT_ADMIN', 'PROJECT_WRITE' and 'PROJECT_READ'
    :return:
    """
    url = "{}/permissions/{}/all".format(self._url_project(project_key), permission)
    return self.post(url, params={"allow": False})

project_remove_group_permissions(project_key, groupname)

Revoke all permissions for the specified project for a group. The authenticated user must have PROJECT_ADMIN permission for the specified project or a higher global permission to call this resource. In addition, a user may not revoke a group's permissions if it will reduce their own permission level. :param project_key: The project key :param groupname: group to be granted :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
532
533
534
535
536
537
538
539
540
541
542
543
544
545
def project_remove_group_permissions(self, project_key, groupname):
    """
    Revoke all permissions for the specified project for a group.
    The authenticated user must have PROJECT_ADMIN permission for the specified project
    or a higher global permission to call this resource.
    In addition, a user may not revoke a group's permissions
    if it will reduce their own permission level.
    :param project_key: The project key
    :param groupname: group to be granted
    :return:
    """
    url = self._url_project_groups(project_key)
    params = {"name": groupname}
    return self.delete(url, params=params)

project_remove_user_permissions(project_key, username)

Revoke all permissions for the specified project for a user. The authenticated user must have PROJECT_ADMIN permission for the specified project or a higher global permission to call this resource. In addition, a user may not revoke their own project permissions if they do not have a higher global permission. :param project_key: The project key :param username: username to be granted :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
483
484
485
486
487
488
489
490
491
492
493
494
495
def project_remove_user_permissions(self, project_key, username):
    """
    Revoke all permissions for the specified project for a user.
    The authenticated user must have PROJECT_ADMIN permission for
    the specified project or a higher global permission to call this resource.
    In addition, a user may not revoke their own project permissions if they do not have a higher global permission.
    :param project_key: The project key
    :param username: username to be granted
    :return:
    """
    url = self._url_project_users(project_key)
    params = {"name": username}
    return self.delete(url, params=params)

project_summary(key)

Get a project summary :param key: The project key

:return: Map with the project information

Source code in server/vendor/atlassian/bitbucket/__init__.py
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def project_summary(self, key):
    """
    Get a project summary
    :param key: The project key

    :return: Map with the project information
    """
    return {
        "key": key,
        "data": self.project(key),
        "users": self.project_users(key),
        "groups": self.project_groups(key),
        "avatar": self.project_avatar(key),
    }

project_users(key, start=0, limit=None, filter_str=None)

Get users with permission in project :param key: The project key :param filter_str: OPTIONAL: users filter string :param start: :param limit: :return: The list of project users

Source code in server/vendor/atlassian/bitbucket/__init__.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def project_users(self, key, start=0, limit=None, filter_str=None):
    """
    Get users with permission in project
    :param key: The project key
    :param filter_str:  OPTIONAL: users filter string
    :param start:
    :param limit:
    :return: The list of project users
    """
    url = self._url_project_users(key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

project_users_with_administrator_permissions(key)

Get project administrators for project :param key: The project key :return: List of project administrators

Source code in server/vendor/atlassian/bitbucket/__init__.py
457
458
459
460
461
462
463
464
465
466
467
468
469
def project_users_with_administrator_permissions(self, key):
    """
    Get project administrators for project
    :param key: The project key
    :return: List of project administrators
    """
    project_administrators = [
        user["user"] for user in self.project_users(key) if user["permission"] == "PROJECT_ADMIN"
    ]
    for group in self.project_groups_with_administrator_permissions(key):
        for user in self.group_members(group):
            project_administrators.append(user)
    return project_administrators

reindex()

Rebuild the bundled Elasticsearch indexes for Bitbucket Server :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
 98
 99
100
101
102
103
104
def reindex(self):
    """
    Rebuild the bundled Elasticsearch indexes for Bitbucket Server
    :return:
    """
    url = self.resource_url("sync", api_root="rest/indexing", api_version="latest")
    return self.post(url)

reindex_repo(project_key, repository_slug)

Reindex repo :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
def reindex_repo(self, project_key, repository_slug):
    """
    Reindex repo
    :param project_key:
    :param repository_slug:
    :return:
    """
    url = "{urlRepo}/sync".format(
        urlRepo=self._url_repo(
            project_key,
            repository_slug,
            api_root="rest/indexing",
            api_version="1.0",
        )
    )
    return self.post(url)

reindex_repo_dev_panel(project_key, repository_slug)

Reindex all the Jira issues related to this repository_slug, including branches and pull requests. This automatically happens as part of an upgrade, and calling this manually should only be required if something unforeseen happens and the index becomes out of sync. The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource. :param project_key: :param repository_slug: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
834
835
836
837
838
839
840
841
842
843
844
845
def reindex_repo_dev_panel(self, project_key, repository_slug):
    """
    Reindex all the Jira issues related to this repository_slug, including branches and pull requests.
    This automatically happens as part of an upgrade, and calling this manually should only be required
    if something unforeseen happens and the index becomes out of sync.
    The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
    :param project_key:
    :param repository_slug:
    :return:
    """
    url = "{}/reindex".format(self._url_repo(project_key, repository_slug, api_root="rest/jira-dev"))
    return self.post(url)

remove_mail_sender_address()

Clears the server email address. The authenticated user must have the ADMIN permission to call this resource. :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
188
189
190
191
192
193
194
195
def remove_mail_sender_address(self):
    """
    Clears the server email address.
    The authenticated user must have the ADMIN permission to call this resource.
    :return:
    """
    url = self._url_mail_server_sender_address()
    return self.delete(url)

reopen_pull_request(project_key, repository_slug, pr_id, pr_version)

Re-open a declined pull request. The authenticated user must have REPO_READ permission for the repository that this pull request targets to call this resource.

:param project_key: PROJECT :param repository_slug: my_shiny_repo :param pr_id: 2341 :param pr_version: 12 :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
def reopen_pull_request(self, project_key, repository_slug, pr_id, pr_version):
    """
    Re-open a declined pull request.
    The authenticated user must have REPO_READ permission for the repository
    that this pull request targets to call this resource.

    :param project_key: PROJECT
    :param repository_slug: my_shiny_repo
    :param pr_id: 2341
    :param pr_version: 12
    :return:
    """
    url = "{}/reopen".format(self._url_pull_request(project_key, repository_slug, pr_id))
    params = {"version": pr_version}
    return self.post(url, params=params)

repo_all_list(project_key)

Get all repositories list from project :param project_key: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
771
772
773
774
775
776
777
def repo_all_list(self, project_key):
    """
    Get all repositories list from project
    :param project_key:
    :return:
    """
    return self.repo_list(project_key, limit=None)

repo_exists(project_key, repository_slug)

Check if given combination of project and repository exists and available. :param project_key: Key of the project where to check for repository. :param repository_slug: url-compatible repository identifier to look for. :return: False is requested repository doesn't exist in the project or not accessible to the requestor

Source code in server/vendor/atlassian/bitbucket/__init__.py
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
def repo_exists(self, project_key, repository_slug):
    """
    Check if given combination of project and repository exists and available.
    :param project_key: Key of the project where to check for repository.
    :param repository_slug: url-compatible repository identifier to look for.
    :return: False is requested repository doesn't exist in the project or not accessible to the requestor
    """
    exists = False
    try:
        self.get_repo(project_key, repository_slug)
        exists = True
    except HTTPError as e:
        if e.response.status_code in (401, 404):
            pass
    return exists

repo_grant_group_permissions(project_key, repo_key, groupname, permission)

Grant the specified repository permission to a specific group Promote or demote a group's permission level for the specified repository. Available repository permissions are: REPO_READ REPO_WRITE REPO_ADMIN See the Bitbucket Server documentation for a detailed explanation of what each permission entails. The authenticated user must have REPO_ADMIN permission for the specified repository or a higher project or global permission to call this resource. In addition, a user may not demote a group's permission level if their own permission level would be reduced as a result. :param project_key: The project key :param repo_key: The repository key (slug) :param groupname: group to be granted :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
def repo_grant_group_permissions(self, project_key, repo_key, groupname, permission):
    """
    Grant the specified repository permission to a specific group
    Promote or demote a group's permission level for the specified repository. Available repository permissions are:
        REPO_READ
        REPO_WRITE
        REPO_ADMIN
    See the Bitbucket Server documentation for a detailed explanation of what each permission entails.
    The authenticated user must have REPO_ADMIN permission for the specified repository or a higher project
    or global permission to call this resource.
    In addition, a user may not demote a group's permission level
    if their own permission level would be reduced as a result.
    :param project_key: The project key
    :param repo_key: The repository key (slug)
    :param groupname: group to be granted
    :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
    :return:
    """
    url = self._url_repo_groups(project_key, repo_key)
    params = {"permission": permission, "name": groupname}
    return self.put(url, params=params)

repo_grant_user_permissions(project_key, repo_key, username, permission)

Grant the specified repository permission to a specific user :param project_key: The project key :param repo_key: The repository key (slug) :param username: username to be granted :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
976
977
978
979
980
981
982
983
984
985
986
987
def repo_grant_user_permissions(self, project_key, repo_key, username, permission):
    """
    Grant the specified repository permission to a specific user
    :param project_key: The project key
    :param repo_key: The repository key (slug)
    :param username: username to be granted
    :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
    :return:
    """
    url = self._url_repo_users(project_key, repo_key)
    params = {"permission": permission, "name": username}
    return self.put(url, params=params)

repo_groups(project_key, repo_key, start=0, limit=None, filter_str=None)

Get repository Groups :param start: :param limit: :param project_key: The project key :param repo_key: The repository key :param filter_str: OPTIONAL: group filter string :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
def repo_groups(self, project_key, repo_key, start=0, limit=None, filter_str=None):
    """
    Get repository Groups
    :param start:
    :param limit:
    :param project_key: The project key
    :param repo_key: The repository key
    :param filter_str: OPTIONAL: group filter string
    :return:
    """
    url = self._url_repo_groups(project_key, repo_key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

repo_groups_with_administrator_permissions(project_key, repo_key)

Get groups with admin permissions :param project_key: :param repo_key: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
def repo_groups_with_administrator_permissions(self, project_key, repo_key):
    """
    Get groups with admin permissions
    :param project_key:
    :param repo_key:
    :return:
    """
    repo_group_administrators = []
    for group in self.repo_groups(project_key, repo_key):
        if group["permission"] == "REPO_ADMIN":
            repo_group_administrators.append(group["group"]["name"])
    for group in self.project_groups_with_administrator_permissions(project_key):
        repo_group_administrators.append(group)
    # We convert to a set to ensure uniqueness, then back to a list for later useability
    return list(set(repo_group_administrators))

repo_keys(project_key, repo_key, start=0, limit=None, filter_str=None)

Get SSH access keys added to the repository :param start: :param limit: :param project_key: The project key :param repo_key: The repository key :param filter_str: OPTIONAL: users filter string :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
def repo_keys(self, project_key, repo_key, start=0, limit=None, filter_str=None):
    """
    Get SSH access keys added to the repository
    :param start:
    :param limit:
    :param project_key: The project key
    :param repo_key: The repository key
    :param filter_str:  OPTIONAL: users filter string
    :return:
    """
    url = "{}/ssh".format(self._url_repo(project_key, repo_key, api_root="rest/keys"))
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

repo_list(project_key, start=0, limit=25)

Get repositories list from project

:param project_key: The project key :param start: :param limit: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
def repo_list(self, project_key, start=0, limit=25):
    """
    Get repositories list from project

    :param project_key: The project key
    :param start:
    :param limit:
    :return:
    """
    url = self._url_repos(project_key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    return self._get_paged(url, params=params)

repo_remove_group_permissions(project_key, repo_key, groupname, permission)

Revoke all permissions for the specified repository for a group. The authenticated user must have REPO_ADMIN permission for the specified repository or a higher project or global permission to call this resource. In addition, a user may not revoke a group's permissions if it will reduce their own permission level. :param project_key: The project key :param repo_key: The repository key (slug) :param groupname: group to be granted :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
def repo_remove_group_permissions(self, project_key, repo_key, groupname, permission):
    """
    Revoke all permissions for the specified repository for a group.
    The authenticated user must have REPO_ADMIN permission for the specified repository
    or a higher project or global permission to call this resource.
    In addition, a user may not revoke a group's permissions if it will reduce their own permission level.
    :param project_key: The project key
    :param repo_key: The repository key (slug)
    :param groupname: group to be granted
    :param permission: the repository permissions available are 'REPO_ADMIN', 'REPO_WRITE' and 'REPO_READ'
    :return:
    """
    url = self._url_repo_groups(project_key, repo_key)
    params = {"name": groupname}
    if permission:
        params["permission"] = permission
    return self.delete(url, params=params)

repo_remove_user_permissions(project_key, repo_key, username)

Revoke all permissions for the specified repository for a user. The authenticated user must have REPO_ADMIN permission for the specified repository or a higher project or global permission to call this resource. In addition, a user may not revoke their own repository permissions if they do not have a higher project or global permission. :param project_key: The project key :param repo_key: The repository key (slug) :param username: username to be granted :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
def repo_remove_user_permissions(self, project_key, repo_key, username):
    """
    Revoke all permissions for the specified repository for a user.
    The authenticated user must have REPO_ADMIN permission for the specified repository
    or a higher project or global permission to call this resource.
    In addition, a user may not revoke their own repository permissions
    if they do not have a higher project or global permission.
    :param project_key: The project key
    :param repo_key: The repository key (slug)
    :param username: username to be granted
    :return:
    """
    url = self._url_repo_users(project_key, repo_key)
    params = {"name": username}
    return self.delete(url, params=params)

repo_users(project_key, repo_key, start=0, limit=None, filter_str=None)

Get users with permission in repository :param start: :param limit: :param project_key: The project key :param repo_key: The repository key :param filter_str: OPTIONAL: Users filter string :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
def repo_users(self, project_key, repo_key, start=0, limit=None, filter_str=None):
    """
    Get users with permission in repository
    :param start:
    :param limit:
    :param project_key: The project key
    :param repo_key: The repository key
    :param filter_str:  OPTIONAL: Users filter string
    :return:
    """
    url = self._url_repo_users(project_key, repo_key)
    params = {}
    if start:
        params["start"] = start
    if limit:
        params["limit"] = limit
    if filter_str:
        params["filter"] = filter_str
    return self._get_paged(url, params=params)

repo_users_with_administrator_permissions(project_key, repo_key)

Get repository administrators for repository :param project_key: The project key :param repo_key: The repository key :return: List of repo administrators

Source code in server/vendor/atlassian/bitbucket/__init__.py
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
def repo_users_with_administrator_permissions(self, project_key, repo_key):
    """
    Get repository administrators for repository
    :param project_key: The project key
    :param repo_key: The repository key
    :return: List of repo administrators
    """
    repo_administrators = []
    for user in self.repo_users(project_key, repo_key):
        if user["permission"] == "REPO_ADMIN":
            repo_administrators.append(user)
    for group in self.repo_groups_with_administrator_permissions(project_key, repo_key):
        for user in self.group_members(group):
            repo_administrators.append(user)
    for user in self.project_users_with_administrator_permissions(project_key):
        repo_administrators.append(user)
    # We convert to a set to ensure uniqueness then back to a list for later useability
    return list({user["id"]: user for user in repo_administrators}.values())

search_code(team, search_query, page=1, limit=10)

Search repositories for matching code :team: str :search_query: str

Source code in server/vendor/atlassian/bitbucket/__init__.py
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
def search_code(self, team, search_query, page=1, limit=10):
    """
    Search repositories for matching code
    :team: str
    :search_query: str
    """
    url = self.resource_url("teams/{team}/search/code".format(team=team))
    return self.get(
        url,
        params={"search_query": search_query, "page": page, "pagelen": limit},
    )

set_announcement_banner(body)

Sets the announcement banner with the provided JSON. Only users authenticated as Admins may call this resource :param body { "id": "https://docs.atlassian.com/jira/REST/schema/rest-announcement-banner#", "title": "Rest Announcement Banner", "type": "object" } :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def set_announcement_banner(self, body):
    """
    Sets the announcement banner with the provided JSON.
    Only users authenticated as Admins may call this resource
    :param body
        {
            "id": "https://docs.atlassian.com/jira/REST/schema/rest-announcement-banner#",
            "title": "Rest Announcement Banner",
            "type": "object"
        }
    :return:
    """
    url = self._url_announcement_banner()
    return self.put(url, data=body)

set_branches_permissions(project_key, multiple_permissions=False, matcher_type=None, matcher_value=None, permission_type=None, repository_slug=None, except_users=None, except_groups=None, except_access_keys=None, start=0, limit=25)

Create a restriction for the supplied branch or set of branches to be applied to the given repository. Allows creating multiple restrictions at once. To use multiple restrictions you should format payload manually - see the bitbucket-branch-restrictions.py example. Reference: https://docs.atlassian.com/bitbucket-server/rest/6.8.0/bitbucket-ref-restriction-rest.html :param project_key: :param multiple_permissions: :param matcher_type: :param matcher_value: :param permission_type: :param repository_slug: :param except_users: :param except_groups: :param except_access_keys: :param start: :param limit: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
def set_branches_permissions(
    self,
    project_key,
    multiple_permissions=False,
    matcher_type=None,
    matcher_value=None,
    permission_type=None,
    repository_slug=None,
    except_users=None,
    except_groups=None,
    except_access_keys=None,
    start=0,
    limit=25,
):
    """
    Create a restriction for the supplied branch or set of branches to be applied to the given repository.
    Allows creating multiple restrictions at once.
    To use multiple restrictions you should format payload manually -
    see the bitbucket-branch-restrictions.py example.
    Reference: https://docs.atlassian.com/bitbucket-server/rest/6.8.0/bitbucket-ref-restriction-rest.html
    :param project_key:
    :param multiple_permissions:
    :param matcher_type:
    :param matcher_value:
    :param permission_type:
    :param repository_slug:
    :param except_users:
    :param except_groups:
    :param except_access_keys:
    :param start:
    :param limit:
    :return:
    """
    url = self._url_branches_permissions(project_key=project_key, repository_slug=repository_slug)
    if except_users is None:
        except_users = []
    if except_groups is None:
        except_groups = []
    if except_access_keys is None:
        except_access_keys = []
    headers = self.default_headers
    if multiple_permissions:
        headers = self.bulk_headers
        restriction = multiple_permissions
    else:
        restriction = {
            "type": permission_type,
            "matcher": {
                "id": matcher_value,
                "displayId": matcher_value,
                "type": {
                    "id": matcher_type.upper(),
                    "name": matcher_type.capitalize(),
                },
                "active": True,
            },
            "users": except_users,
            "groups": except_groups,
            "accessKeys": except_access_keys,
        }
    params = {"start": start, "limit": limit}
    return self.post(url, data=restriction, params=params, headers=headers)

set_branching_model(project_key, repository_slug, data)

Set branching model :param project_key: :param repository_slug: :param data: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
def set_branching_model(self, project_key, repository_slug, data):
    """
    Set branching model
    :param project_key:
    :param repository_slug:
    :param data:
    :return:
    """
    url = self._url_branching_model(project_key, repository_slug)
    return self.put(url, data=data)

set_default_branch(project_key, repository_slug, ref_branch_name)

Update the default branch of a repository. The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource. :param project_key: The project key :param repository_slug: The repository key (slug) :param ref_branch_name: ref name like refs/heads/master :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
def set_default_branch(self, project_key, repository_slug, ref_branch_name):
    """
    Update the default branch of a repository.
    The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
    :param project_key: The project key
    :param repository_slug: The repository key (slug)
    :param ref_branch_name: ref name like refs/heads/master
    :return:
    """
    url = self._url_repo_default_branche(project_key, repository_slug)
    data = {"id": ref_branch_name}
    return self.put(url, data=data)

set_project_avatar(key, icon, content_type='image/png')

Set project avatar :param key: The Project key :param icon: The icon file :param content_type: The content type of icon

:return: Value of post request

Source code in server/vendor/atlassian/bitbucket/__init__.py
402
403
404
405
406
407
408
409
410
411
412
413
414
def set_project_avatar(self, key, icon, content_type="image/png"):
    """
    Set project avatar
    :param key: The Project key
    :param icon: The icon file
    :param content_type: The content type of icon

    :return: Value of post request
    """
    url = self._url_project_avatar(key)
    headers = {"X-Atlassian-Token": "no-check"}
    files = {"avatar": ("avatar.png", icon, content_type)}
    return self.post(url, files=files, headers=headers)

set_pull_request_settings(project_key, repository_slug, data)

Set pull request settings. :param project_key: :param repository_slug: :param data: json body :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
def set_pull_request_settings(self, project_key, repository_slug, data):
    """
    Set pull request settings.
    :param project_key:
    :param repository_slug:
    :param data: json body
    :return:
    """
    url = self._url_pull_request_settings(project_key, repository_slug)
    return self.post(url, data=data)

set_repo_label(project_key, repository_slug, label_name)

Sets a label on a repository. (BitBucket Server only) The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource. :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :param label_name: label name to apply :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
def set_repo_label(self, project_key, repository_slug, label_name):
    """
    Sets a label on a repository. (BitBucket Server only)
    The authenticated user must have REPO_ADMIN permission for the specified repository to call this resource.
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :param label_name: label name to apply
    :return:
    """
    url = self._url_repo_labels(project_key, repository_slug)
    data = {"name": label_name}
    return self.post(url, data=data)

set_tag(project_key, repository_slug, tag_name, commit_revision, description=None)

Creates a tag using the information provided in the {@link RestCreateTagRequest request} The authenticated user must have REPO_WRITE permission for the context repository to call this resource. :param project_key: :param repository_slug: :param tag_name: :param commit_revision: commit hash :param description: OPTIONAL: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
def set_tag(
    self,
    project_key,
    repository_slug,
    tag_name,
    commit_revision,
    description=None,
):
    """
    Creates a tag using the information provided in the {@link RestCreateTagRequest request}
    The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param tag_name:
    :param commit_revision: commit hash
    :param description: OPTIONAL:
    :return:
    """
    url = self._url_repo_tags(project_key, repository_slug)
    body = {
        "name": tag_name,
        "startPoint": commit_revision,
    }
    if description is not None:
        body["message"] = description

    return self.post(url, data=body)

stop_pipeline(workspace, repository_slug, uuid)

Stop the pipeline specified by uuid. :param workspace: :param repository_slug: :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)

See the documentation for the meaning of response status codes.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def stop_pipeline(self, workspace, repository_slug, uuid):
    """
    Stop the pipeline specified by ``uuid``.
    :param workspace:
    :param repository_slug:
    :param uuid: Pipeline identifier (with surrounding {}; NOT the build number)

    See the documentation for the meaning of response status codes.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.get(uuid)
        .stop()
    )

trigger_pipeline(workspace, repository_slug, branch='master', revision=None, name=None)

Trigger a new pipeline. The following options are possible (1 and 2 trigger the pipeline that the branch is associated with in the Pipelines configuration): 1. Latest revision of a branch (specify branch) 2. Specific revision on a branch (additionally specify revision) 3. Specific pipeline (additionally specify name) :return: the initiated pipeline; or error information

Source code in server/vendor/atlassian/bitbucket/__init__.py
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def trigger_pipeline(
    self,
    workspace,
    repository_slug,
    branch="master",
    revision=None,
    name=None,
):
    """
    Trigger a new pipeline. The following options are possible (1 and 2
    trigger the pipeline that the branch is associated with in the Pipelines
    configuration):
    1. Latest revision of a branch (specify ``branch``)
    2. Specific revision on a branch (additionally specify ``revision``)
    3. Specific pipeline (additionally specify ``name``)
    :return: the initiated pipeline; or error information
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .pipelines.trigger(branch=branch, commit=revision, pattern=name)
        .data
    )

update_branch_restriction(workspace, repository_slug, id, **fields)

Update an existing branch restriction identified by id. Consult the official API documentation for valid fields.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def update_branch_restriction(self, workspace, repository_slug, id, **fields):
    """
    Update an existing branch restriction identified by ``id``.
    Consult the official API documentation for valid fields.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .branch_restrictions.get(id)
        .update(**fields)
        .data
    )

update_file(project_key, repository_slug, content, message, branch, filename, source_commit_id)

Update existing file for given branch. :param project_key: :param repository_slug: :param content: :param message: :param branch: :param filename: :param source_commit_id: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
def update_file(
    self,
    project_key,
    repository_slug,
    content,
    message,
    branch,
    filename,
    source_commit_id,
):
    """
    Update existing file for given branch.
    :param project_key:
    :param repository_slug:
    :param content:
    :param message:
    :param branch:
    :param filename:
    :param source_commit_id:
    :return:
    """
    url = self._url_file(project_key, repository_slug, filename)
    data = {
        "content": content,
        "message": message,
        "branch": branch,
        "sourceCommitId": source_commit_id,
    }
    return self.put(url, files=data, headers={"Accept": "application/json"})

update_issue(workspace, repository_slug, id, **fields)

Update the fields of the issue specified by id. Consult the official API documentation for valid fields.

Source code in server/vendor/atlassian/bitbucket/__init__.py
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
@deprecated(
    version="2.0.2",
    reason="Use atlassian.bitbucket.cloud instead of atlassian.bitbucket",
)
def update_issue(self, workspace, repository_slug, id, **fields):
    """
    Update the ``fields`` of the issue specified by ``id``.
    Consult the official API documentation for valid fields.
    """
    return (
        Cloud(self.url, **self._new_session_args)
        .workspaces.get(workspace)
        .repositories.get(repository_slug)
        .issues.get(id)
        .update(**fields)
        .data
    )

update_project(key, **params)

Update project :param key: The project key :return: The value of the put request.

Source code in server/vendor/atlassian/bitbucket/__init__.py
360
361
362
363
364
365
366
367
def update_project(self, key, **params):
    """
    Update project
    :param key: The project key
    :return: The value of the put request.
    """
    url = self._url_project(key)
    return self.put(url, data=params)

update_project_condition(project_key, condition, id_condition)

Request type: PUT Update a new condition for this project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632 :projectKey: str- project key involved :idCondition: int - condition id involved :data: condition: dictionary object :example condition: '{"sourceMatcher": {"id":"any", "type":{"id":"ANY_REF"}}, "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}}, "reviewers":[{"id": 12}],"requiredApprovals":"0" }' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
def update_project_condition(self, project_key, condition, id_condition):
    """
    Request type: PUT
    Update a new condition for this project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
    :projectKey: str- project key involved
    :idCondition: int - condition id involved
    :data: condition: dictionary object
    :example condition: '{"sourceMatcher":
                            {"id":"any",
                            "type":{"id":"ANY_REF"}},
                            "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                            "reviewers":[{"id": 12}],"requiredApprovals":"0"
                        }'
    :return:
    """
    url = self._url_project_condition(project_key, id_condition)
    return self.put(url, data=condition) or {}

update_pull_request(project_key, repository_slug, pull_request_id, data)

Update a pull request. The authenticated user must have REPO_WRITE permission for the repository that this pull request targets to call this resource. :param project_key: :param repository_slug: :param pull_request_id: the ID of the pull request within the repository :param data: json body :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
def update_pull_request(self, project_key, repository_slug, pull_request_id, data):
    """
    Update a pull request.
    The authenticated user must have REPO_WRITE permission
    for the repository that this pull request targets to call this resource.
    :param project_key:
    :param repository_slug:
    :param pull_request_id: the ID of the pull request within the repository
    :param data: json body
    :return:
    """

    url = self._url_pull_request(project_key, repository_slug, pull_request_id)
    return self.put(url, data=data)

update_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id, comment, comment_version)

Update the text of a comment. Only the user who created a comment may update it.

Note: the supplied JSON object must contain a version that must match the server's version of the comment or the update will fail.

Source code in server/vendor/atlassian/bitbucket/__init__.py
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
def update_pull_request_comment(
    self,
    project_key,
    repository_slug,
    pull_request_id,
    comment_id,
    comment,
    comment_version,
):
    """
    Update the text of a comment.
    Only the user who created a comment may update it.

    Note: the supplied JSON object must contain a version
    that must match the server's version of the comment
    or the update will fail.
    """
    url = self._url_pull_request_comment(project_key, repository_slug, pull_request_id, comment_id)
    data = {"version": comment_version, "text": comment}
    return self.put(url, data=data)

update_repo(project_key, repository_slug, **params)

Update a repository in a project. This operates based on slug not name which may be confusing to some users. :param project_key: Key of the project you wish to look in. :param repository_slug: url-compatible repository identifier :return: The value of the put request.

Source code in server/vendor/atlassian/bitbucket/__init__.py
874
875
876
877
878
879
880
881
882
883
def update_repo(self, project_key, repository_slug, **params):
    """
    Update a repository in a project. This operates based on slug not name which may
    be confusing to some users.
    :param project_key: Key of the project you wish to look in.
    :param repository_slug: url-compatible repository identifier
    :return: The value of the put request.
    """
    url = self._url_repo(project_key, repository_slug)
    return self.put(url, data=params)

update_repo_condition(project_key, repo_key, condition, id_condition)

Request type: PUT Update a specific condition for this repository slug inside project. For further information visit: https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632 :projectKey: str- project key involved :repoKey: str - repo key involved :idCondition: int - condition id involved :data: condition: dictionary object :example condition: '{"sourceMatcher": {"id":"any", "type":{"id":"ANY_REF"}}, "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}}, "reviewers":[{"id": 12}],"requiredApprovals":"0" }' :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
def update_repo_condition(self, project_key, repo_key, condition, id_condition):
    """
    Request type: PUT
    Update a specific condition for this repository slug inside project.
    For further information visit:
        https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-default-reviewers-rest.html#idm52264927632
    :projectKey: str- project key involved
    :repoKey: str - repo key involved
    :idCondition: int - condition id involved
    :data: condition: dictionary object
    :example condition: '{"sourceMatcher":
                            {"id":"any",
                            "type":{"id":"ANY_REF"}},
                            "targetMatcher":{"id":"refs/heads/master","type":{"id":"BRANCH"}},
                            "reviewers":[{"id": 12}],"requiredApprovals":"0"
                        }'
    :return:
    """
    url = self._url_repo_condition(project_key, repo_key, id_condition)
    return self.put(url, data=condition) or {}

update_task(task_id, text=None, state=None)

Update task by ID. It is possible to update state and/or text of the task :param task_id: :param text: :param state: OPEN, RESOLVED :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
def update_task(self, task_id, text=None, state=None):
    """
    Update task by ID. It is possible to update state and/or text of the task
    :param task_id:
    :param text:
    :param state: OPEN, RESOLVED
    :return:
    """
    url = self._url_task(task_id)
    data = {"id": task_id}
    if text:
        data["text"] = text
    if state:
        data["state"] = state
    return self.put(url, data=data)

update_webhook(project_key, repository_slug, webhook_id, **params)

Update a webhook. The authenticated user must have REPO_ADMIN permission for the context repository to call this resource. :param project_key: :param repository_slug: :param webhook_id: the ID of the webhook within the repository :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
def update_webhook(self, project_key, repository_slug, webhook_id, **params):
    """
    Update a webhook.
    The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
    :param project_key:
    :param repository_slug:
    :param webhook_id: the ID of the webhook within the repository
    :return:
    """
    url = self._url_webhook(project_key, repository_slug, webhook_id)
    return self.put(url, data=params)

upload_file(project_key, repository_slug, content, message, branch, filename)

Upload new file for given branch. :param project_key: :param repository_slug: :param content: :param message: :param branch: :param filename :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
def upload_file(self, project_key, repository_slug, content, message, branch, filename):
    """
    Upload new file for given branch.
    :param project_key:
    :param repository_slug:
    :param content:
    :param message:
    :param branch:
    :param filename
    :return:
    """
    url = self._url_file(project_key, repository_slug, filename)
    data = {"content": content, "message": message, "branch": branch}
    return self.put(url, files=data, headers={"Accept": "application/json"})

upload_plugin(plugin_path)

Provide plugin path for upload into BitBucket e.g. useful for auto deploy :param plugin_path: :return:

Source code in server/vendor/atlassian/bitbucket/__init__.py
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def upload_plugin(self, plugin_path):
    """
    Provide plugin path for upload into BitBucket e.g. useful for auto deploy
    :param plugin_path:
    :return:
    """
    upm_token = self.request(
        method="GET",
        path="rest/plugins/1.0/",
        headers=self.no_check_headers,
        trailing=True,
    ).headers["upm-token"]
    url = "rest/plugins/1.0/?token={}".format(upm_token)
    files = {"plugin": open(plugin_path, "rb")}
    return self.post(url, files=files, headers=self.no_check_headers)