gitbak 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/gitbak/services.rb +35 -6
- data/lib/gitbak/version.rb +2 -2
- metadata +7 -7
data/README.md
CHANGED
data/lib/gitbak/services.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# File : gitbak/services.rb
|
4
4
|
# Maintainer : Felix C. Stegerman <flx@obfusk.net>
|
5
|
-
# Date : 2013-
|
5
|
+
# Date : 2013-03-20
|
6
6
|
#
|
7
7
|
# Copyright : Copyright (C) 2013 Felix C. Stegerman
|
8
8
|
# Licence : GPLv2
|
@@ -40,6 +40,19 @@ module GitBak
|
|
40
40
|
gist: ->(user) { "api.github.com/users/#{user}/gists" },
|
41
41
|
}
|
42
42
|
|
43
|
+
# github pagination
|
44
|
+
GH_PAGES = ->(data; l, n, r) {
|
45
|
+
(l = data.meta['link']) &&
|
46
|
+
(n = l.split(',').grep(/rel="next"/).first) &&
|
47
|
+
(r = l.match(%r{<(https://[^>]*)>})) && r[1]
|
48
|
+
}
|
49
|
+
|
50
|
+
# pagination
|
51
|
+
PAGES = { github: GH_PAGES, gist: GH_PAGES }
|
52
|
+
|
53
|
+
# JSON pages concat
|
54
|
+
JCAT = ->(pages) { pages.map { |x| JSON.load x } .flatten 1 }
|
55
|
+
|
43
56
|
# remote urls
|
44
57
|
REMOTES = # {{{1
|
45
58
|
{
|
@@ -64,9 +77,8 @@ module GitBak
|
|
64
77
|
|
65
78
|
# get data from API
|
66
79
|
# @raise AuthError on 401
|
67
|
-
def self.
|
68
|
-
|
69
|
-
opts = auth ? { AUTH => [auth[:user], auth[:pass]] } : {}
|
80
|
+
def self.api_get_ (url, auth) # {{{1
|
81
|
+
opts = auth ? { AUTH => [auth[:user], auth[:pass]] } : {}
|
70
82
|
|
71
83
|
begin
|
72
84
|
data = open url, opts
|
@@ -82,6 +94,23 @@ module GitBak
|
|
82
94
|
data
|
83
95
|
end # }}}1
|
84
96
|
|
97
|
+
# paginate
|
98
|
+
def self.paginate (pag, url, &b)
|
99
|
+
pages = []
|
100
|
+
while url; pages << data = b[url]; url = pag[data]; end
|
101
|
+
pages
|
102
|
+
end
|
103
|
+
|
104
|
+
# get data from API (w/ pagination if necessary); see api_get_
|
105
|
+
# @return [String]
|
106
|
+
# @return [<String>] if paginated
|
107
|
+
def self.api_get (service, user, auth)
|
108
|
+
url = "https://#{APIS[service][user]}"
|
109
|
+
pag = PAGES[service]
|
110
|
+
pag ? paginate(pag, url) { |u| api_get_ u, auth }
|
111
|
+
: api_get_(url, auth)
|
112
|
+
end
|
113
|
+
|
85
114
|
# get repositories from service; uses api_get if service in APIS,
|
86
115
|
# api_get_<service> otherwise
|
87
116
|
#
|
@@ -108,7 +137,7 @@ module GitBak
|
|
108
137
|
|
109
138
|
# turn github API data into a list of repositories
|
110
139
|
def self.github (cfg, data, rem)
|
111
|
-
|
140
|
+
JCAT[data].map do |r|
|
112
141
|
{ name: r['name'], remote: rem[cfg[:user], r['name']],
|
113
142
|
description: r['description'] }
|
114
143
|
end
|
@@ -116,7 +145,7 @@ module GitBak
|
|
116
145
|
|
117
146
|
# turn gist API data into a list of repositories
|
118
147
|
def self.gist (cfg, data, rem)
|
119
|
-
|
148
|
+
JCAT[data].map do |r|
|
120
149
|
{ name: r['id'], remote: rem[r['id']],
|
121
150
|
description: r['description'] }
|
122
151
|
end
|
data/lib/gitbak/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitbak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &16348360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16348360
|
25
25
|
description: ! 'GitBak mirrors Bitbucket/GitHub/Gist repositories; paths, users,
|
26
26
|
|
27
27
|
and authentication are specified in ~/.gitbak.
|
@@ -50,13 +50,13 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- bin/gitbak
|
52
52
|
- gitbak.gemspec
|
53
|
-
- lib/gitbak
|
54
|
-
- lib/gitbak/config.rb
|
53
|
+
- lib/gitbak.rb
|
55
54
|
- lib/gitbak/version.rb
|
56
55
|
- lib/gitbak/misc.rb
|
57
56
|
- lib/gitbak/eval.rb
|
57
|
+
- lib/gitbak/config.rb
|
58
58
|
- lib/gitbak/services.rb
|
59
|
-
- lib/gitbak.rb
|
59
|
+
- lib/gitbak/exec.rb
|
60
60
|
homepage: https://github.com/obfusk/gitbak
|
61
61
|
licenses:
|
62
62
|
- GPLv2
|