Skip to content

Commit 33d04f8

Browse files
Viktor bergnaestia
authored andcommitted
Changed logic to not include --output-file flag as well as smaller changes.
1 parent c50aad9 commit 33d04f8

File tree

3 files changed

+15
-88
lines changed

3 files changed

+15
-88
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ subgit delete
100100
subgit delete pykwalify
101101
```
102102
103-
## Import repos from Github or Gitlab
103+
## Inspect repos from Github or Gitlab
104104
105-
You can import a list of repos and create a new or overwrite an existing configuration file. Getting access to this command, two things need to be prepared. If these requirements are not met, the command will return an error and exit.
105+
If the user wants all repos from a group or account to be written to a file, subgit offers a way to do this by using 'subgit inspect'. This prints all repos in a finished rendered subgit config file format (yaml) to stdout. Redirect the output to a file to get a correct subgit cofiguration file. By default 'subgit inspect' excludes archived repos and those not owned by the specified user. Use '--archived' flag to filter for only archived repos.
106106
107107
### Authentication for github cli
108108
@@ -119,14 +119,14 @@ Next generate a new private API token for your account in gitlab. Create one her
119119
Export your token in your terminal with `export GITLAB_PRIVATE_TOKEN=<YOUR TOKEN>` and it will allow for api access. Test this by running `gitlab projects list`
120120
121121
```bash
122-
# Import all repos from github and write them to '.subgit.yml'
123-
subgit import github <YOUR_USERNAME>
122+
# Inspect all repos from github and write them to '.subgit.yml'
123+
subgit inspect github <YOUR_USERNAME>
124124
125-
# Import all repos from gitlab and write them to '.subgit.yml'
126-
subgit import gitlab <YOUR_USERNAME>
125+
# Inspect all repos from gitlab and write them to '.subgit.yml'
126+
subgit inspect gitlab <YOUR_USERNAME>
127127
128-
# You can redirect the output to another file with -o flag
129-
subgit import github <YOUR_USERNAME> -o .some-other-file.yml
128+
# You can redirect the output to another file
129+
subgit inspect github <YOUR_USERNAME> > .some-other-file.yml
130130
```
131131
132132
## Reset changed repos

subgit/cli.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@
112112
subgit inspect (github | gitlab) <owner> [options]
113113
114114
Options:
115-
-y, --yes Answers yes to all questions (use with caution)
116-
-o <filename>, --output-file <filename> Used if inspect output should be directed to a .subgit.yml file
117115
-a, --archived Writes only archived repos to output file
118116
-h, --help Show this help message and exit
119117
@@ -272,8 +270,6 @@ def run(cli_args, sub_args):
272270

273271
if cli_args["<command>"] == "inspect":
274272
git_inspect = GitInspect(
275-
config_file_name=sub_args.get("--output-file"),
276-
answer_yes=sub_args["--yes"],
277273
is_archived=sub_args.get("--archived"),
278274
)
279275
github = sub_args["github"]

subgit/inspect/git_inspect.py

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@
1717

1818

1919
class GitInspect(SubGit):
20-
def __init__(self, config_file_name=None, answer_yes=None, is_archived=False):
21-
self.answer_yes = answer_yes
20+
def __init__(self, is_archived=False):
2221
self.is_archived = is_archived
23-
self.config_file_name = config_file_name
24-
25-
# Defaults config file to '.subgit-github.yml' if nothing is specified
26-
if not config_file_name:
27-
self.subgit_config_file_name = ".subgit.yml"
28-
29-
if self.is_archived:
30-
self.subgit_config_file_name = ".subgit-archived.yml"
31-
else:
32-
self.subgit_config_file_name = config_file_name
33-
34-
self.subgit_config_file_path = os.path.join(os.getcwd(), self.subgit_config_file_name)
3522

3623
def _cli_installed(self, source):
3724
"""
@@ -110,37 +97,9 @@ def inspect_github(self, owner):
11097
"url": repo_data["sshUrl"],
11198
}
11299

113-
# If no config file name specfied, example file will be written to stdout
114-
if not self.config_file_name:
115-
log.info("Your '.subgit.yml' file would look like this:")
116-
log.info("repos:")
117-
118-
for repo in repos:
119-
branch = repos[repo]["revision"]["branch"]
120-
url = repos[repo]["url"]
121-
log.info(f" {repo}:")
122-
log.info(f" revision:")
123-
log.info(f" branch: {branch}")
124-
log.info(f" url: {url}")
125-
126-
return 0
127-
128-
# If config file name specified, inspect command will look for the file and ask for
129-
# confirmation whether user wants to overwrite this file
130-
if os.path.exists(self.subgit_config_file_path):
131-
answer = self.yes_no(f"File: {self.subgit_config_file_path} already exists on disk, do you want to overwrite the file?")
132-
133-
if not answer:
134-
log.error("Aborting writing to file...")
135-
return 1
136-
137-
yml = yaml.YAML()
138-
yml.indent(mapping=2, sequence=4, offset=2)
139-
with open(self.subgit_config_file_path, "w") as stream:
140-
yml.dump({"repos": repos}, stream)
141-
142-
log.info(f"Successfully wrote to file: {self.subgit_config_file_name}")
143-
return 0
100+
yaml_output = yaml.dump({"repos": repos}, default_flow_style=False, indent=2)
101+
102+
print(yaml_output)
144103

145104
def inspect_gitlab(self, owner):
146105
"""
@@ -191,34 +150,6 @@ def inspect_gitlab(self, owner):
191150
"url": repo_data["ssh_url_to_repo"],
192151
}
193152

194-
# If no config file name specfied, example file will be written to stdout
195-
if not self.config_file_name:
196-
log.info("Your '.subgit.yml' file would look like this:")
197-
log.info("repos:")
198-
199-
for repo in repos:
200-
branch = repos[repo]["revision"]["branch"]
201-
url = repos[repo]["url"]
202-
log.info(f" {repo}:")
203-
log.info(f" revision:")
204-
log.info(f" branch: {branch}")
205-
log.info(f" url: {url}")
206-
207-
return 0
208-
209-
# If config file name specified, inspect command will look for the file and ask for
210-
# confirmation whether user wants to overwrite this file
211-
if os.path.exists(self.subgit_config_file_path):
212-
answer = self.yes_no(f"File: {self.subgit_config_file_path} already exists on disk, do you want to overwrite the file?")
213-
214-
if not answer:
215-
log.error("Aborting writing to file...")
216-
return 1
217-
218-
yml = yaml.YAML()
219-
yml.indent(mapping=2, sequence=4, offset=2)
220-
with open(self.subgit_config_file_path, "w") as stream:
221-
yml.dump({"repos": repos}, stream)
222-
223-
log.info(f"Successfully wrote to file: {self.subgit_config_file_name}")
224-
return 0
153+
yaml_output = yaml.dump({"repos": repos}, default_flow_style=False, indent=2)
154+
155+
print(yaml_output)

0 commit comments

Comments
 (0)