Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rcfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
rcfiles
Commits
a8ceb1fe
Commit
a8ceb1fe
authored
3 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Some more functionality to the git and gitlab submodules.
parent
6a6904bb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Documents/bin/rcfiles/git.py
+71
-0
71 additions, 0 deletions
Documents/bin/rcfiles/git.py
Documents/bin/rcfiles/gitlab.py
+6
-0
6 additions, 0 deletions
Documents/bin/rcfiles/gitlab.py
with
77 additions
and
0 deletions
Documents/bin/rcfiles/git.py
+
71
−
0
View file @
a8ceb1fe
"""
Git repository related functions.
"""
"""
Git repository related functions.
"""
import
configparser
import
os.path
import
os.path
import
pathlib
import
pathlib
from
sh.contrib
import
git
# pylint: disable=import-error
from
.
import
gitlab
def
is_repo
(
path
):
def
is_repo
(
path
):
...
@@ -18,3 +21,71 @@ def in_repo():
...
@@ -18,3 +21,71 @@ def in_repo():
it
'
s enough to just check if the .git directory exists where we are.
it
'
s enough to just check if the .git directory exists where we are.
"""
"""
return
is_repo
(
"
.
"
)
return
is_repo
(
"
.
"
)
def
get_remotes
():
"""
Return a dictionary of remotes and their URL.
Also, deduce the remote type (
"
gitlab
"
,
"
github
"
or None if couldn
'
t figure
it out) and get the namespace and repository name.
If not in a Git repository, return None.
"""
if
not
in_repo
:
return
None
gitlab_http_url
=
gitlab
.
get_url
()
gitlab_ssh_url
=
(
f
'
git@
{
gitlab_http_url
.
removeprefix
(
"
https
:
//
"
).removesuffix(
"
/
"
)
}
:
'
)
github_http_url
=
"
https://github.com/
"
github_ssh_url
=
"
git@github.com:
"
config
=
configparser
.
ConfigParser
()
config
.
read
(
"
.git/config
"
)
remotes
=
{
x
.
removeprefix
(
'
remote
"'
).
removesuffix
(
'"'
):
{
"
url
"
:
config
[
x
][
"
url
"
],
"
name
"
:
x
.
removeprefix
(
'
remote
"'
).
removesuffix
(
'"'
),
}
for
x
in
config
.
sections
()
if
x
.
startswith
(
"
remote
"
)
}
for
name
,
remote
in
remotes
.
items
():
if
remote
[
"
url
"
].
startswith
(
gitlab_http_url
)
or
remote
[
"
url
"
].
startswith
(
gitlab_ssh_url
):
remotes
[
name
][
"
type
"
]
=
"
gitlab
"
parts
=
(
remote
[
"
url
"
]
.
removeprefix
(
gitlab_http_url
)
.
removeprefix
(
gitlab_ssh_url
)
.
removesuffix
(
"
.git
"
)
.
split
(
"
/
"
)
)
if
len
(
parts
)
==
2
:
remotes
[
name
][
"
namespace
"
]
=
parts
[
0
]
remotes
[
name
][
"
name
"
]
=
parts
[
1
]
elif
remote
[
"
url
"
].
startswith
(
github_http_url
)
or
remote
[
"
url
"
].
startswith
(
github_ssh_url
):
remotes
[
name
][
"
type
"
]
=
"
github
"
parts
=
(
remote
[
"
url
"
]
.
removeprefix
(
github_http_url
)
.
removeprefix
(
github_ssh_url
)
.
removesuffix
(
"
.git
"
)
.
split
(
"
/
"
)
)
if
len
(
parts
)
==
2
:
remotes
[
name
][
"
name
"
]
=
parts
[
1
]
else
:
remotes
[
remote
][
"
type
"
]
=
None
return
remotes
def
add_remote
(
name
,
url
):
"""
Add a remote to the Git repository.
"""
git
.
remote
(
"
add
"
,
name
,
url
)
This diff is collapsed.
Click to expand it.
Documents/bin/rcfiles/gitlab.py
+
6
−
0
View file @
a8ceb1fe
...
@@ -77,3 +77,9 @@ def create_project(conn, name, group=None, description=None, visibility=None):
...
@@ -77,3 +77,9 @@ def create_project(conn, name, group=None, description=None, visibility=None):
if
visibility
is
not
None
:
if
visibility
is
not
None
:
data
[
"
visibility
"
]
=
visibility
data
[
"
visibility
"
]
=
visibility
return
conn
.
projects
.
create
(
data
)
return
conn
.
projects
.
create
(
data
)
def
read_only_project
(
conn
,
group
,
name
):
"""
Make a GitLab project read-only.
"""
project
=
get_project
(
conn
,
group
,
name
)
project
.
archive
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment