Skip to content

Commit ee6384d

Browse files
committed
👍 Merge branch devel ; 🔖 Version bump to 1.8.0
🚧 Features * Support for insecure connection through config option (fixes #66) * Made gitlab feature complete: * Added support for list command in gitlab (cf #78) * Added support for gitlab gists (fixes #12) * Added support for gitlab merge requests (fixes #10) 🚒 Bugfixes * Bad exceptions handling mistakes (fixes #84, fixes #85) * Missing edge case handling in list command (fixes #83) 💄 Cosmetics * Updated README with new config option * Added @rnestler to contributors * Updated TODO list Signed-off-by: Guyzmo <[email protected]>
2 parents 0ffa4b5 + 25c3561 commit ee6384d

File tree

47 files changed

+3037
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3037
-105
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ Also, you can setup your own GitLab self-hosted server, using that configuration
173173
type = gitlab
174174
token = YourSuperPrivateKey
175175
fqdn = gitlab.example.org
176+
# Set this only if you use a self-signed certificate and experience problems
177+
insecure = true
176178

177179
Finally, to make it really cool, you can make a few aliases in your gitconfig:
178180

@@ -186,6 +188,20 @@ So you can run the tool as a git subcommand:
186188

187189
git hub clone guyzmo/git-repo
188190

191+
For those who like to keep all dotfiles in a git repository, it'd be horrendous to
192+
store tokens that offer access to your social accounts in a repository… And I'm not
193+
even talking about those who want to share your dotfiles. But don't worry, once
194+
it's all configured, you can fire up your [favorite editor](http://www.vim.org) and
195+
move all the `[gitrepo …]` sections into a new file, like `~/.gitconfig-repos`.
196+
197+
Your can run the following command to do this automagically:
198+
199+
python -m git_repo.extract_config
200+
201+
if you want to use another path, you can change the defaults:
202+
203+
python -m git_repo.extract_config ~/.gitconfig-repos ~/.gitconfig
204+
189205
### Development
190206

191207
For development, I like to use `buildout`, and the repository is already configured
@@ -253,13 +269,13 @@ To use your own credentials, you can setup the following environment variables:
253269
* [x] show a nice progress bar, while it's fetching (cf [#15](https://github.com/guyzmo/git-repo/issues/15))
254270
* [ ] add support for handling gists
255271
* [x] github support
256-
* [ ] gitlab support (cf [#12](https://github.com/guyzmo/git-repo/issues/12))
272+
* [x] gitlab support (cf [#12](https://github.com/guyzmo/git-repo/issues/12))
257273
* [ ] bitbucket support (cf [#13](https://github.com/guyzmo/git-repo/issues/13))
258274
* [ ] add support for handling pull requests
259275
* [x] github support
260-
* [ ] gitlab support (cf [#10](https://github.com/guyzmo/git-repo/issues/10))
276+
* [x] gitlab support (cf [#10](https://github.com/guyzmo/git-repo/issues/10))
261277
* [ ] bitbucket support (cf [#11](https://github.com/guyzmo/git-repo/issues/11))
262-
* [ ] add OAuth support for bitbucket (cf [#14](https://github.com/guyzmo/git-repo/issues/14))
278+
* [ ] add application token support for bitbucket (cf [#14](https://github.com/guyzmo/git-repo/issues/14))
263279
* [ ] add support for managing SSH keys (cf [#22](https://github.com/guyzmo/git-repo/issues/22))
264280
* [ ] add support for issues?
265281
* [ ] add support for gogs (cf [#18](https://github.com/guyzmo/git-repo/issues/18))
@@ -279,6 +295,7 @@ With code contributions coming from:
279295
* [@buaazp](https://github.com/buaazp)[commits](https://github.com/guyzmo/git-repo/commits?author=buaazp)
280296
* [@peterazmanov](https://github.com/peterazmanov)[commits](https://github.com/guyzmo/git-repo/commits?author=peterazmanov)
281297
* [@Crazybus](https://github.com/Crazybus)[commits](https://github.com/guyzmo/git-repo/commits?author=Crazybus)
298+
* [@rnestler](https://github.com/rnestler)[commits](https://github.com/guyzmo/git-repo/commits/devel?author=rnestler)
282299

283300
### License
284301

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.7.5
1+
1.8.0

buildout.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ develop-eggs-directory = ${buildout:directory}/var/develop-eggs
99
parts-directory = ${buildout:directory}/var/parts
1010
# develop-dir = ${buildout:directory}/var/clone/
1111
# extensions=gp.vcsdevelop
12-
# vcs-extend-develop=git+https://github.com/gitpython-developers/GitPython#egg=GitPython
12+
# vcs-extend-develop=git+https://github.com/…@…#egg=
1313

1414
[git_repo]
1515
recipe = zc.recipe.egg

git_repo/extract_config.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import git
6+
7+
def extract_gitrepo_sections(conf):
8+
return filter(lambda k: k.startswith('gitrepo'), conf.sections())
9+
10+
def extract_gitrepo_conf(gconf_old, gconf_new):
11+
if os.path.exists(gconf_new):
12+
return "✗ cannot execute, file already exists: {}".format(gconf_new)
13+
with git.config.GitConfigParser(gconf_old, read_only=False) as cold:
14+
with git.config.GitConfigParser(gconf_new, read_only=False) as cnew:
15+
sections = list(extract_gitrepo_sections(cold))
16+
# copy the sections to the new configuration file
17+
cnew.update({s: {k:v for k,v in cold.items(s)} for s in sections})
18+
cnew.write()
19+
# remove the sections from the old configuration file
20+
for section in sections:
21+
cold.remove_section(section)
22+
# insert path to the new config file in the old one
23+
cold.update({'include': {'path': os.path.abspath(gconf_new)}})
24+
print("🍻 git-repo configuration extracted to new file: {}".format(gconf_new))
25+
26+
if __name__ == '__main__':
27+
if '-h' in sys.argv or '--help' in sys.argv:
28+
sys.exit('Usage: {} [.gitconfig-repos] [.gitconfig]'.format(sys.argv[0]))
29+
sys.exit(extract_gitrepo_conf(
30+
gconf_old=os.path.expanduser(len(sys.argv) >= 3 and sys.argv[2] or '~/.gitconfig'),
31+
gconf_new=os.path.expanduser(len(sys.argv) >= 2 and sys.argv[1] or '~/.gitconfig-repos')
32+
))
33+
34+

git_repo/repo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
print('Please use with python version 3')
135135
sys.exit(1)
136136

137-
from .exceptions import ArgumentError
137+
from .exceptions import ArgumentError, ResourceNotFoundError
138138
from .services.service import RepositoryService
139139

140140
from .kwargparse import KeywordArgumentParser, store_parameter, register_action
@@ -438,12 +438,14 @@ def do_request_fetch(self):
438438
@register_action('snippet', 'list')
439439
def do_gist_list(self):
440440
service = self.get_service(lookup_repository=False)
441-
if self.gist_ref:
441+
if 'github' == service.name and self.gist_ref:
442442
log.info("{:15}\t{:>7}\t{}".format('language', 'size', 'name'))
443+
else:
444+
log.info("{:56}\t{}".format('id', 'title'.ljust(60)))
445+
if self.gist_ref:
443446
for gist_file in service.gist_list(self.gist_ref):
444447
print("{:15}\t{:7}\t{}".format(*gist_file))
445448
else:
446-
log.info("{:56}\t{}".format('id', 'title'.ljust(60)))
447449
for gist in service.gist_list():
448450
print( "{:56}\t{}".format(gist[0], gist[1]))
449451
return 0

git_repo/services/ext/github.py

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,52 @@ def col_print(lines, indent=0, pad=2):
107107
else:
108108
print('Status\tCommits\tReqs\tIssues\tForks\tCoders\tWatch\tLikes\tLang\tModif\t\tName', file=sys.stderr)
109109
for repo in repositories:
110-
if repo.updated_at.year < datetime.now().year:
111-
date_fmt = "%b %d %Y"
112-
else:
113-
date_fmt = "%b %d %H:%M"
114-
115-
status = ''.join([
116-
'F' if repo.fork else ' ', # is a fork?
117-
'P' if repo.private else ' ', # is private?
118-
])
119-
print('\t'.join([
120-
# status
121-
status,
122-
# stats
123-
str(len(list(repo.iter_commits()))), # number of commits
124-
str(len(list(repo.iter_pulls()))), # number of pulls
125-
str(len(list(repo.iter_issues()))), # number of issues
126-
str(repo.forks), # number of forks
127-
str(len(list(repo.iter_contributors()))), # number of contributors
128-
str(repo.watchers), # number of subscribers
129-
str(repo.stargazers or 0), # number of ♥
130-
# info
131-
repo.language or '?', # language
132-
repo.updated_at.strftime(date_fmt), # date
133-
'/'.join([user, repo.name]), # name
134-
]))
135-
136-
137-
138-
110+
try:
111+
if repo.updated_at.year < datetime.now().year:
112+
date_fmt = "%b %d %Y"
113+
else:
114+
date_fmt = "%b %d %H:%M"
115+
116+
status = ''.join([
117+
'F' if repo.fork else ' ', # is a fork?
118+
'P' if repo.private else ' ', # is private?
119+
])
120+
print('\t'.join([
121+
# status
122+
status,
123+
# stats
124+
str(len(list(repo.iter_commits()))), # number of commits
125+
str(len(list(repo.iter_pulls()))), # number of pulls
126+
str(len(list(repo.iter_issues()))), # number of issues
127+
str(repo.forks), # number of forks
128+
str(len(list(repo.iter_contributors()))), # number of contributors
129+
str(repo.watchers), # number of subscribers
130+
str(repo.stargazers or 0), # number of ♥
131+
# info
132+
repo.language or '?', # language
133+
repo.updated_at.strftime(date_fmt), # date
134+
'/'.join([user, repo.name]), # name
135+
]))
136+
except Exception as err:
137+
if 'Git Repository is empty.' == err.args[0].json()['message']:
138+
print('\t'.join([
139+
# status
140+
'E',
141+
# stats
142+
'ø', # number of commits
143+
'ø', # number of pulls
144+
'ø', # number of issues
145+
'ø', # number of forks
146+
'ø', # number of contributors
147+
'ø', # number of subscribers
148+
'ø', # number of ♥
149+
# info
150+
'?', # language
151+
repo.updated_at.strftime(date_fmt), # date
152+
'/'.join([user, repo.name]), # name
153+
]))
154+
else:
155+
print("Cannot show repository {}: {}".format('/'.join([user, repo.name]), err))
139156

140157
def get_repository(self, user, repo):
141158
repository = self.gh.repository(user, repo)
@@ -249,7 +266,7 @@ def request_fetch(self, user, repo, request, pull=False):
249266
try:
250267
for remote in self.repository.remotes:
251268
if remote.name == self.name:
252-
local_branch_name = 'request/{}'.format(request)
269+
local_branch_name = 'requests/github/{}'.format(request)
253270
self.fetch(
254271
remote,
255272
'pull/{}/head'.format(request),

0 commit comments

Comments
 (0)