Skip to content

Commit 545f8ed

Browse files
committed
chore: rename master branch to main
BREAKING CHANGE: As of python-gitlab 3.0.0, the default branch for development has changed from `master` to `main`.
1 parent 5a1678f commit 545f8ed

30 files changed

+81
-77
lines changed

.github/workflows/docs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Docs
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9+
- main
910
- master
1011

1112
env:

.github/workflows/lint.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Lint
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9+
- main
910
- master
1011

1112
env:

.github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Test
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9+
- main
910
- master
1011

1112
env:

README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
.. image:: https://readthedocs.org/projects/python-gitlab/badge/?version=latest
88
:target: https://python-gitlab.readthedocs.org/en/latest/?badge=latest
99

10-
.. image:: https://codecov.io/github/python-gitlab/python-gitlab/coverage.svg?branch=master
11-
:target: https://codecov.io/github/python-gitlab/python-gitlab?branch=master
10+
.. image:: https://codecov.io/github/python-gitlab/python-gitlab/coverage.svg?branch=main
11+
:target: https://codecov.io/github/python-gitlab/python-gitlab?branch=main
1212

1313
.. image:: https://img.shields.io/pypi/pyversions/python-gitlab.svg
1414
:target: https://pypi.python.org/pypi/python-gitlab
@@ -96,4 +96,4 @@ You can build the documentation using ``sphinx``::
9696
Contributing
9797
============
9898

99-
For guidelines for contributing to ``python-gitlab``, refer to `CONTRIBUTING.rst <https://github.com/python-gitlab/python-gitlab/blob/master/CONTRIBUTING.rst>`_.
99+
For guidelines for contributing to ``python-gitlab``, refer to `CONTRIBUTING.rst <https://github.com/python-gitlab/python-gitlab/blob/main/CONTRIBUTING.rst>`_.

docs/gl_objects/branches.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Get the list of branches for a repository::
2222

2323
Get a single repository branch::
2424

25-
branch = project.branches.get('master')
25+
branch = project.branches.get('main')
2626

2727
Create a repository branch::
2828

2929
branch = project.branches.create({'branch': 'feature1',
30-
'ref': 'master'})
30+
'ref': 'main'})
3131

3232
Delete a repository branch::
3333

docs/gl_objects/commits.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Create a commit::
4040
# See https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
4141
# for actions detail
4242
data = {
43-
'branch': 'master',
43+
'branch': 'main',
4444
'commit_message': 'blah blah blah',
4545
'actions': [
4646
{

docs/gl_objects/deployments.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Create a new deployment::
2929
deployment = project.deployments.create({
3030
"environment": "Test",
3131
"sha": "1agf4gs",
32-
"ref": "master",
32+
"ref": "main",
3333
"tag": False,
3434
"status": "created",
3535
})

docs/gl_objects/mrs.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Get a single MR::
9494
Create a MR::
9595

9696
mr = project.mergerequests.create({'source_branch': 'cool_feature',
97-
'target_branch': 'master',
97+
'target_branch': 'main',
9898
'title': 'merge cool feature',
9999
'labels': ['label1', 'label2']})
100100

docs/gl_objects/pipelines_and_jobs.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Get variables of a pipeline::
3535

3636
Create a pipeline for a particular reference with custom variables::
3737

38-
pipeline = project.pipelines.create({'ref': 'master', 'variables': [{'key': 'MY_VARIABLE', 'value': 'hello'}]})
38+
pipeline = project.pipelines.create({'ref': 'main', 'variables': [{'key': 'MY_VARIABLE', 'value': 'hello'}]})
3939

4040
Retry the failed builds for a pipeline::
4141

@@ -97,7 +97,7 @@ Full example with wait for finish::
9797
return project.triggers.create({'description': trigger_decription})
9898

9999
trigger = get_or_create_trigger(project)
100-
pipeline = project.trigger_pipeline('master', trigger.token, variables={"DEPLOY_ZONE": "us-west1"})
100+
pipeline = project.trigger_pipeline('main', trigger.token, variables={"DEPLOY_ZONE": "us-west1"})
101101
while pipeline.finished_at is None:
102102
pipeline.refresh()
103103
time.sleep(1)
@@ -108,7 +108,7 @@ objects to get the associated project::
108108

109109
gl = gitlab.Gitlab(URL) # no authentication
110110
project = gl.projects.get(project_id, lazy=True) # no API call
111-
project.trigger_pipeline('master', trigger_token)
111+
project.trigger_pipeline('main', trigger_token)
112112

113113
Reference: https://docs.gitlab.com/ee/ci/triggers/#trigger-token
114114

@@ -146,7 +146,7 @@ Get a single schedule::
146146
Create a new schedule::
147147

148148
sched = project.pipelineschedules.create({
149-
'ref': 'master',
149+
'ref': 'main',
150150
'description': 'Daily test',
151151
'cron': '0 1 * * *'})
152152

@@ -213,7 +213,7 @@ Examples
213213
Jobs are usually automatically triggered, but you can explicitly trigger a new
214214
job::
215215

216-
project.trigger_build('master', trigger_token,
216+
project.trigger_build('main', trigger_token,
217217
{'extra_var1': 'foo', 'extra_var2': 'bar'})
218218

219219
List jobs for the project::
@@ -247,7 +247,7 @@ Get the artifacts of a job::
247247
Get the artifacts of a job by its name from the latest successful pipeline of
248248
a branch or tag:
249249

250-
project.artifacts(ref_name='master', job='build')
250+
project.artifacts(ref_name='main', job='build')
251251

252252
.. warning::
253253

docs/gl_objects/projects.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Update a project submodule::
158158

159159
items = project.update_submodule(
160160
submodule="foo/bar",
161-
branch="master",
161+
branch="main",
162162
commit_sha="4c3674f66071e30b3311dac9b9ccc90502a72664",
163163
commit_message="Message", # optional
164164
)
@@ -199,7 +199,7 @@ Get a snapshot of the repository::
199199

200200
Compare two branches, tags or commits::
201201

202-
result = project.repository_compare('master', 'branch1')
202+
result = project.repository_compare('main', 'branch1')
203203

204204
# get the commits
205205
for commit in result['commits']:
@@ -340,7 +340,7 @@ Examples
340340

341341
Get a file::
342342

343-
f = project.files.get(file_path='README.rst', ref='master')
343+
f = project.files.get(file_path='README.rst', ref='main')
344344

345345
# get the base64 encoded content
346346
print(f.content)
@@ -350,15 +350,15 @@ Get a file::
350350
351351
Get a raw file::
352352
353-
raw_content = project.files.raw(file_path='README.rst', ref='master')
353+
raw_content = project.files.raw(file_path='README.rst', ref='main')
354354
print(raw_content)
355355
with open('/tmp/raw-download.txt', 'wb') as f:
356-
project.files.raw(file_path='README.rst', ref='master', streamed=True, action=f.write)
356+
project.files.raw(file_path='README.rst', ref='main', streamed=True, action=f.write)
357357

358358
Create a new file::
359359

360360
f = project.files.create({'file_path': 'testfile.txt',
361-
'branch': 'master',
361+
'branch': 'main',
362362
'content': file_content,
363363
'author_email': 'test@example.com',
364364
'author_name': 'yourname',
@@ -369,23 +369,23 @@ Update a file. The entire content must be uploaded, as plain text or as base64
369369
encoded text::
370370

371371
f.content = 'new content'
372-
f.save(branch='master', commit_message='Update testfile')
372+
f.save(branch='main', commit_message='Update testfile')
373373

374374
# or for binary data
375375
# Note: decode() is required with python 3 for data serialization. You can omit
376376
# it with python 2
377377
f.content = base64.b64encode(open('image.png').read()).decode()
378-
f.save(branch='master', commit_message='Update testfile', encoding='base64')
378+
f.save(branch='main', commit_message='Update testfile', encoding='base64')
379379

380380
Delete a file::
381381

382-
f.delete(commit_message='Delete testfile', branch='master')
382+
f.delete(commit_message='Delete testfile', branch='main')
383383
# or
384-
project.files.delete(file_path='testfile.txt', commit_message='Delete testfile', branch='master')
384+
project.files.delete(file_path='testfile.txt', commit_message='Delete testfile', branch='main')
385385

386386
Get file blame::
387387

388-
b = project.files.blame(file_path='README.rst', ref='master')
388+
b = project.files.blame(file_path='README.rst', ref='main')
389389

390390
Project tags
391391
============
@@ -414,7 +414,7 @@ Get a tag::
414414

415415
Create a tag::
416416

417-
tag = project.tags.create({'tag_name': '1.0', 'ref': 'master'})
417+
tag = project.tags.create({'tag_name': '1.0', 'ref': 'main'})
418418

419419
Delete a tag::
420420

@@ -702,7 +702,7 @@ Get project push rules (returns None is there are no push rules)::
702702

703703
Edit project push rules::
704704

705-
pr.branch_name_regex = '^(master|develop|support-\d+|release-\d+\..+|hotfix-.+|feature-.+)$'
705+
pr.branch_name_regex = '^(main|develop|support-\d+|release-\d+\..+|hotfix-.+|feature-.+)$'
706706
pr.save()
707707

708708
Delete project push rules::

docs/gl_objects/protected_branches.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Get the list of protected branches for a project::
2525

2626
Get a single protected branch::
2727

28-
p_branch = project.protectedbranches.get('master')
28+
p_branch = project.protectedbranches.get('main')
2929

3030
Create a protected branch::
3131

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module = [
2929
ignore_errors = false
3030

3131
[tool.semantic_release]
32+
branch = "main"
3233
version_variable = "gitlab/__version__.py:__version__"
3334
commit_subject = "chore: release v{version}"
3435
commit_message = ""

tests/functional/api/test_merge_requests.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def test_merge_requests(project):
1010
project.files.create(
1111
{
1212
"file_path": "README.rst",
13-
"branch": "master",
13+
"branch": "main",
1414
"content": "Initial content",
1515
"commit_message": "Initial commit",
1616
}
1717
)
1818

1919
source_branch = "branch1"
20-
project.branches.create({"branch": source_branch, "ref": "master"})
20+
project.branches.create({"branch": source_branch, "ref": "main"})
2121

2222
project.files.create(
2323
{
@@ -28,7 +28,7 @@ def test_merge_requests(project):
2828
}
2929
)
3030
project.mergerequests.create(
31-
{"source_branch": "branch1", "target_branch": "master", "title": "MR readme2"}
31+
{"source_branch": "branch1", "target_branch": "main", "title": "MR readme2"}
3232
)
3333

3434

tests/functional/api/test_projects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_project_stars(project):
240240

241241

242242
def test_project_tags(project, project_file):
243-
tag = project.tags.create({"tag_name": "v1.0", "ref": "master"})
243+
tag = project.tags.create({"tag_name": "v1.0", "ref": "main"})
244244
assert len(project.tags.list()) == 1
245245

246246
tag.delete()

tests/functional/api/test_repository.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ def test_repository_files(project):
1010
project.files.create(
1111
{
1212
"file_path": "README",
13-
"branch": "master",
13+
"branch": "main",
1414
"content": "Initial content",
1515
"commit_message": "Initial commit",
1616
}
1717
)
18-
readme = project.files.get(file_path="README", ref="master")
18+
readme = project.files.get(file_path="README", ref="main")
1919
readme.content = base64.b64encode(b"Improved README").decode()
2020

2121
time.sleep(2)
22-
readme.save(branch="master", commit_message="new commit")
23-
readme.delete(commit_message="Removing README", branch="master")
22+
readme.save(branch="main", commit_message="new commit")
23+
readme.delete(commit_message="Removing README", branch="main")
2424

2525
project.files.create(
2626
{
2727
"file_path": "README.rst",
28-
"branch": "master",
28+
"branch": "main",
2929
"content": "Initial content",
3030
"commit_message": "New commit",
3131
}
3232
)
33-
readme = project.files.get(file_path="README.rst", ref="master")
33+
readme = project.files.get(file_path="README.rst", ref="main")
3434
# The first decode() is the ProjectFile method, the second one is the bytes
3535
# object method
3636
assert readme.decode().decode() == "Initial content"
3737

38-
blame = project.files.blame(file_path="README.rst", ref="master")
38+
blame = project.files.blame(file_path="README.rst", ref="main")
3939
assert blame
4040

4141

@@ -51,7 +51,7 @@ def test_repository_tree(project):
5151
archive = project.repository_archive()
5252
assert isinstance(archive, bytes)
5353

54-
archive2 = project.repository_archive("master")
54+
archive2 = project.repository_archive("main")
5555
assert archive == archive2
5656

5757
snapshot = project.snapshot()
@@ -60,7 +60,7 @@ def test_repository_tree(project):
6060

6161
def test_create_commit(project):
6262
data = {
63-
"branch": "master",
63+
"branch": "main",
6464
"commit_message": "blah blah blah",
6565
"actions": [{"action": "create", "file_path": "blah", "content": "blah"}],
6666
}
@@ -114,7 +114,7 @@ def test_commit_discussion(project):
114114

115115
def test_revert_commit(project):
116116
commit = project.commits.list()[0]
117-
revert_commit = commit.revert(branch="master")
117+
revert_commit = commit.revert(branch="main")
118118

119119
expected_message = 'Revert "{}"\n\nThis reverts commit {}'.format(
120120
commit.message, commit.id
@@ -123,4 +123,4 @@ def test_revert_commit(project):
123123

124124
with pytest.raises(gitlab.GitlabRevertError):
125125
# Two revert attempts should raise GitlabRevertError
126-
commit.revert(branch="master")
126+
commit.revert(branch="main")

tests/functional/cli/test_cli_artifacts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515
data = {
1616
"file_path": ".gitlab-ci.yml",
17-
"branch": "master",
17+
"branch": "main",
1818
"content": content,
1919
"commit_message": "Initial commit",
2020
}

0 commit comments

Comments
 (0)