Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitLab API Experiments
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
Container 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
Karl Fogel
GitLab API Experiments
Commits
46cfbfe3
Commit
46cfbfe3
authored
1 month ago
by
Karl Fogel
Browse files
Options
Downloads
Patches
Plain Diff
Improve option parsing
parent
ecafcf1c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gl-sak
+28
-13
28 additions, 13 deletions
gl-sak
with
28 additions
and
13 deletions
gl-sak
+
28
−
13
View file @
46cfbfe3
...
...
@@ -7,9 +7,11 @@ entities (issues, labels, milestones, etc) in a GitLab project.
Usage
$ ./gl-sak --
root OWNER[/
PROJECT_PATH] COMMAND [ARGS...]
$ ./gl-sak --
gitlab=GL_SERVER --user USER [--root
PROJECT_PATH] COMMAND [ARGS...]
OWNER/PROJECT_PATH is something like
"
jrandom/foo/bar/myproj
"
.
E.g.,
$ ./gl-sak --user jrandom --gitlab=https://code.librehq.com --root foo/bar/myproj baz qux quux
TBD: Document some commands, some of which take further arguments.
...
...
@@ -76,26 +78,39 @@ def main():
# here would be RawDescriptionHelpFormatter.
formatter_class
=
argparse
.
RawTextHelpFormatter
)
arg_parser
.
add_argument
(
'
--gitlab
'
,
help
=
"
The URL of the GitLab server (not with path appended)
"
)
arg_parser
.
add_argument
(
'
--root
'
,
help
=
"
The root path of the project to operate on
"
)
arg_parser
.
add_argument
(
'
--user
'
,
help
=
"
The username to log in to GitLab with
"
)
authn_token_arg
=
arg_parser
.
add_mutually_exclusive_group
()
authn_token_arg
.
add_argument
(
'
-T
'
,
'
--authn-token
'
,
# TBD: This next one is not implemented yet. Also, how to
# tell argparse that two options are mutually incompatible?
# Do we just have to do that with post-parsing code, or does
# argparse have a built-in way to handle it?
'
-F
'
,
'
--authn-token-file
'
,
help
=
"
The GitLab access token to use for this operation
"
)
authn_token_arg
.
add_argument
(
'
-F
'
,
'
--authn-token-file
'
,
help
=
"
File containing the GitLab access token to use for this operation
"
)
args
=
arg_parser
.
parse_args
()
if
args
.
authn_token_file
is
not
None
:
with
open
(
args
.
authn_token_file
,
"
r
"
)
as
f
:
args
.
authn_token
=
f
.
readline
().
rstrip
()
# Set up the GitLab instance.
l
hq
=
gitlab
.
Gitlab
(
url
=
'
https://code.librehq.com
'
,
g
l
=
gitlab
.
Gitlab
(
url
=
args
.
gitlab
,
private_token
=
args
.
authn_token
)
l
hq
.
auth
()
g
l
.
auth
()
# WARNING: Turning on debugging can cause credentials and other
# sensitive data to be printed on the console.
#
# l
hq
.enable_debug()
#
g
l.enable_debug()
projects
=
l
hq
.
projects
.
list
(
iterator
=
True
)
projects
=
g
l
.
projects
.
list
(
iterator
=
True
)
for
project
in
projects
:
print
(
f
"
***
{
project
.
name_with_namespace
}
(
{
project
.
id
}
):
"
)
issues
=
project
.
issues
.
list
(
get_all
=
True
)
...
...
@@ -103,13 +118,13 @@ def main():
# print(f"{issue}")
print
(
""
)
groups
=
l
hq
.
groups
.
list
(
iterator
=
True
)
groups
=
g
l
.
groups
.
list
(
iterator
=
True
)
for
group
in
groups
:
print
(
f
"
{
group
}
"
)
# This isn't quite right yet:
#
# boards = l
hq
.boards.list(iterator=True)
# boards =
g
l.boards.list(iterator=True)
# for board in boards:
# print(f"*** {board} ({board.id}):")
...
...
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