github-release-party 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/github-release-party.rb +89 -45
- data/lib/github-release-party/tasks/heroku.rb +11 -5
- data/lib/github-release-party/version.rb +2 -4
- metadata +2 -17
- metadata.gz.sig +0 -0
- data/lib/http.rb +0 -143
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46459e03534d4da5df10a808417f51a63861b1afe9ed97d3d800fe99a66473f3
|
4
|
+
data.tar.gz: 0ca9805a23cbe728b590f670d20e5775f1c38b567f076451fe3677af006c41d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08fe94d85b1a42f13691b5a48350e2f2b7b9f5d82be8997870bf36fb583879a1ca004e6165f6f3e88ade5a30e2d4de144cab2ab138419fe64a4e4cf971d48fce'
|
7
|
+
data.tar.gz: 24c33ae1483107e18925678c27058a098cd298f69e16e9b50cc0dc7cf006fd3f8a9522a8a98ec9968395a4c8472a58aec379daf0ef7777295d1cd67837db0f39
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/github-release-party.rb
CHANGED
@@ -1,65 +1,44 @@
|
|
1
|
-
require_relative "http"
|
2
1
|
require_relative "github-release-party/version"
|
3
2
|
|
4
|
-
class GithubReleaseParty
|
5
|
-
|
6
|
-
|
7
|
-
HEADERS = {
|
8
|
-
"User-Agent" => "github-release-party/#{GithubReleaseParty::VERSION}",
|
9
|
-
}
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
return unless self.class.env_ok
|
13
|
-
@releases = []
|
3
|
+
class GithubReleaseParty
|
4
|
+
def self.releases
|
5
|
+
releases = []
|
14
6
|
page = 1
|
15
7
|
while true
|
16
|
-
r =
|
17
|
-
|
8
|
+
r = GitHub.get("/repos/#{repo}/releases?page=#{page}")
|
9
|
+
if !r.success?
|
10
|
+
puts "Error occurred when fetching releases:"
|
11
|
+
puts error(r)
|
12
|
+
abort
|
13
|
+
end
|
18
14
|
break if r.json.length == 0
|
19
|
-
|
20
|
-
@releases = @releases + r.json
|
15
|
+
releases = releases + r.json
|
21
16
|
page += 1
|
22
17
|
end
|
23
|
-
|
24
|
-
|
25
|
-
def update_or_create(tag_name, name, message)
|
26
|
-
release = @releases.find { |rel| rel["tag_name"] == tag_name }
|
27
|
-
if release
|
28
|
-
self.class.update(release["id"], name, message)
|
29
|
-
else
|
30
|
-
self.class.create(tag_name, name, message)
|
31
|
-
end
|
18
|
+
return releases
|
32
19
|
end
|
33
20
|
|
34
21
|
def self.update(id, name, message)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
name: name,
|
40
|
-
body: message
|
41
|
-
}.to_json
|
42
|
-
})
|
22
|
+
r = GitHub.patch("/repos/#{repo}/releases/#{id}", {
|
23
|
+
name: name,
|
24
|
+
body: message
|
25
|
+
}.to_json)
|
43
26
|
if r.success?
|
44
27
|
puts "GitHub release #{name} updated!"
|
45
28
|
else
|
46
|
-
puts "Failed to update GitHub release #{
|
29
|
+
puts "Failed to update GitHub release #{name}!"
|
47
30
|
puts error(r)
|
48
31
|
end
|
49
32
|
end
|
50
33
|
|
51
34
|
def self.create(tag_name, name, message)
|
52
|
-
return unless env_ok
|
53
|
-
|
54
35
|
body = {
|
55
36
|
tag_name: tag_name,
|
56
37
|
name: name,
|
57
38
|
body: message
|
58
39
|
}
|
59
40
|
|
60
|
-
r = post("/repos/#{repo}/releases",
|
61
|
-
body: body.to_json
|
62
|
-
})
|
41
|
+
r = GitHub.post("/repos/#{repo}/releases", body.to_json)
|
63
42
|
if r.success?
|
64
43
|
puts "GitHub release #{tag_name} created!"
|
65
44
|
else
|
@@ -76,16 +55,13 @@ class GithubReleaseParty < HTTP
|
|
76
55
|
end
|
77
56
|
end
|
78
57
|
|
79
|
-
def self.
|
58
|
+
def self.check_env!
|
80
59
|
if !ENV["GITHUB_RELEASE_TOKEN"]
|
81
|
-
|
82
|
-
return false
|
60
|
+
abort "Configure GITHUB_RELEASE_TOKEN to create GitHub releases. See https://github.com/stefansundin/github-release-party#setup"
|
83
61
|
end
|
84
62
|
if !repo
|
85
|
-
|
86
|
-
return false
|
63
|
+
abort "Can't find the GitHub repo. Please use the remote 'origin'."
|
87
64
|
end
|
88
|
-
return true
|
89
65
|
end
|
90
66
|
|
91
67
|
def self.repo
|
@@ -95,6 +71,74 @@ class GithubReleaseParty < HTTP
|
|
95
71
|
private
|
96
72
|
|
97
73
|
def self.error(r)
|
98
|
-
"#{r.
|
74
|
+
"#{r.request_uri}: #{r.code}: #{r.body}\nHeaders: #{r.headers.to_json}"
|
75
|
+
end
|
76
|
+
|
77
|
+
class GitHub
|
78
|
+
def self.get(*args)
|
79
|
+
request(:request_get, *args)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.post(*args)
|
83
|
+
request(:request_post, *args)
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.patch(*args)
|
87
|
+
request(:patch, *args)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def self.request(method, request_uri, body=nil)
|
93
|
+
opts = {
|
94
|
+
use_ssl: true,
|
95
|
+
open_timeout: 10,
|
96
|
+
read_timeout: 10,
|
97
|
+
}
|
98
|
+
Net::HTTP.start("api.github.com", 443, opts) do |http|
|
99
|
+
headers = {
|
100
|
+
"Authorization" => "token #{ENV["GITHUB_RELEASE_TOKEN"]}",
|
101
|
+
"User-Agent" => "github-release-party/#{GithubReleaseParty::VERSION}",
|
102
|
+
}
|
103
|
+
if method == :request_post or method == :patch
|
104
|
+
# response = http.send(:request_get, "/", headers)
|
105
|
+
response = http.send(method, request_uri, body, headers)
|
106
|
+
else
|
107
|
+
response = http.send(method, request_uri, headers)
|
108
|
+
end
|
109
|
+
return HTTPResponse.new(response, request_uri)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
class HTTPResponse
|
115
|
+
def initialize(response, request_uri)
|
116
|
+
@response = response
|
117
|
+
@request_uri = request_uri
|
118
|
+
end
|
119
|
+
|
120
|
+
def request_uri
|
121
|
+
@request_uri
|
122
|
+
end
|
123
|
+
|
124
|
+
def body
|
125
|
+
@response.body
|
126
|
+
end
|
127
|
+
|
128
|
+
def json
|
129
|
+
@json ||= JSON.parse(@response.body)
|
130
|
+
end
|
131
|
+
|
132
|
+
def headers
|
133
|
+
@response.to_hash
|
134
|
+
end
|
135
|
+
|
136
|
+
def code
|
137
|
+
@response.code.to_i
|
138
|
+
end
|
139
|
+
|
140
|
+
def success?
|
141
|
+
@response.is_a?(Net::HTTPSuccess)
|
142
|
+
end
|
99
143
|
end
|
100
144
|
end
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
|
55
55
|
desc "Deploy a new version to Heroku"
|
56
56
|
task :deploy do
|
57
|
-
|
57
|
+
GithubReleaseParty.check_env!
|
58
58
|
ver = heroku_push() or abort("Deploy failed.")
|
59
59
|
hash = `git rev-parse HEAD`.strip
|
60
60
|
github_tag(hash, ver)
|
@@ -63,7 +63,7 @@ end
|
|
63
63
|
namespace :deploy do
|
64
64
|
desc "Deploy a new version to Heroku using --force"
|
65
65
|
task :force do
|
66
|
-
|
66
|
+
GithubReleaseParty.check_env!
|
67
67
|
ver = heroku_push(%w[--force]) or abort("Deploy failed.")
|
68
68
|
hash = `git rev-parse HEAD`.strip
|
69
69
|
github_tag(hash, ver)
|
@@ -71,7 +71,7 @@ namespace :deploy do
|
|
71
71
|
|
72
72
|
desc "Tag last release"
|
73
73
|
task :tag do
|
74
|
-
|
74
|
+
GithubReleaseParty.check_env!
|
75
75
|
|
76
76
|
# get heroku version number
|
77
77
|
begin
|
@@ -87,7 +87,8 @@ namespace :deploy do
|
|
87
87
|
|
88
88
|
desc "Rebuild all the release tags"
|
89
89
|
task :retag do
|
90
|
-
|
90
|
+
GithubReleaseParty.check_env!
|
91
|
+
releases = GithubReleaseParty.releases
|
91
92
|
repo = GithubReleaseParty.repo
|
92
93
|
|
93
94
|
tags = `git tag -l heroku/v* --sort=version:refname`.split("\n")
|
@@ -116,7 +117,12 @@ namespace :deploy do
|
|
116
117
|
abort if not success
|
117
118
|
|
118
119
|
# update or create GitHub release
|
119
|
-
|
120
|
+
release = releases.find { |rel| rel["tag_name"] == tag_name }
|
121
|
+
if release
|
122
|
+
GithubReleaseParty.update(release["id"], ver, message)
|
123
|
+
else
|
124
|
+
GithubReleaseParty.create(tag_name, ver, message)
|
125
|
+
end
|
120
126
|
end
|
121
127
|
|
122
128
|
puts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-release-party
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Sundin
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
E04BZKo2WzOTzSDymo97Yu4YFgyc98umMyeaCvPk4YmdNzqSanAXpY2bnsyu0CF5
|
32
32
|
Td0=
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2019-09
|
34
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
@@ -47,20 +47,6 @@ dependencies:
|
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '12'
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: addressable
|
52
|
-
requirement: !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - "~>"
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: '2'
|
57
|
-
type: :runtime
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
requirements:
|
61
|
-
- - "~>"
|
62
|
-
- !ruby/object:Gem::Version
|
63
|
-
version: '2'
|
64
50
|
description: I use this gem to automatically create GitHub releases when I deploy
|
65
51
|
to Heroku. See the GitHub page for usage.
|
66
52
|
email:
|
@@ -72,7 +58,6 @@ files:
|
|
72
58
|
- lib/github-release-party.rb
|
73
59
|
- lib/github-release-party/tasks/heroku.rb
|
74
60
|
- lib/github-release-party/version.rb
|
75
|
-
- lib/http.rb
|
76
61
|
homepage: https://github.com/stefansundin/github-release-party
|
77
62
|
licenses:
|
78
63
|
- GPL-3.0
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/http.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "net/http"
|
4
|
-
require "addressable/uri"
|
5
|
-
require "json"
|
6
|
-
|
7
|
-
class HTTP
|
8
|
-
def self.request(method, url, options={body: nil, headers: nil, query: nil})
|
9
|
-
relative_url = (url[0] == "/")
|
10
|
-
|
11
|
-
if defined?(self::BASE_URL) and relative_url
|
12
|
-
url = self::BASE_URL+url
|
13
|
-
end
|
14
|
-
|
15
|
-
if defined?(self::PARAMS) and relative_url
|
16
|
-
if url["?"]
|
17
|
-
url += "&"+self::PARAMS
|
18
|
-
else
|
19
|
-
url += "?"+self::PARAMS
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if options[:query]
|
24
|
-
params = options[:query].map { |k,v| "#{k}=#{v}" }.join("&")
|
25
|
-
if url["?"]
|
26
|
-
url += "&"+params
|
27
|
-
else
|
28
|
-
url += "?"+params
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
uri = Addressable::URI.parse(url).normalize
|
33
|
-
opts = {
|
34
|
-
use_ssl: uri.scheme == "https",
|
35
|
-
open_timeout: 10,
|
36
|
-
read_timeout: 10,
|
37
|
-
}
|
38
|
-
Net::HTTP.start(uri.host, uri.port, opts) do |http|
|
39
|
-
headers = {}
|
40
|
-
headers.merge!(self::HEADERS) if defined?(self::HEADERS) and relative_url
|
41
|
-
headers.merge!(options[:headers]) if options[:headers]
|
42
|
-
if method == :request_post or method == :patch
|
43
|
-
response = http.send(method, uri.request_uri, options[:body], headers)
|
44
|
-
else
|
45
|
-
response = http.send(method, uri.request_uri, headers)
|
46
|
-
end
|
47
|
-
return HTTPResponse.new(response, uri.to_s)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.get(*args)
|
52
|
-
request(:request_get, *args)
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.post(*args)
|
56
|
-
request(:request_post, *args)
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.patch(*args)
|
60
|
-
request(:patch, *args)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class HTTPResponse
|
65
|
-
def initialize(response, url)
|
66
|
-
@response = response
|
67
|
-
@url = url
|
68
|
-
end
|
69
|
-
|
70
|
-
def raw
|
71
|
-
@response
|
72
|
-
end
|
73
|
-
|
74
|
-
def url
|
75
|
-
@url
|
76
|
-
end
|
77
|
-
|
78
|
-
def body
|
79
|
-
@response.body
|
80
|
-
end
|
81
|
-
|
82
|
-
def json
|
83
|
-
@json ||= JSON.parse(@response.body)
|
84
|
-
end
|
85
|
-
|
86
|
-
def parsed_response
|
87
|
-
json
|
88
|
-
end
|
89
|
-
|
90
|
-
def headers
|
91
|
-
@response.header
|
92
|
-
end
|
93
|
-
|
94
|
-
def code
|
95
|
-
@response.code.to_i
|
96
|
-
end
|
97
|
-
|
98
|
-
def success?
|
99
|
-
@response.is_a?(Net::HTTPSuccess)
|
100
|
-
end
|
101
|
-
|
102
|
-
def redirect?
|
103
|
-
@response.is_a?(Net::HTTPRedirection)
|
104
|
-
end
|
105
|
-
|
106
|
-
def redirect_url
|
107
|
-
raise("not a redirect") if !redirect?
|
108
|
-
url = @response.header["location"]
|
109
|
-
if url[0] == "/"
|
110
|
-
# relative redirect
|
111
|
-
uri = Addressable::URI.parse(@url)
|
112
|
-
url = uri.scheme + "://" + uri.host + url
|
113
|
-
elsif /^https?:\/\/./ !~ url
|
114
|
-
raise("bad redirect: #{url}")
|
115
|
-
end
|
116
|
-
Addressable::URI.parse(url).normalize.to_s # Some redirects do not url encode properly, such as http://amzn.to/2aDg49F
|
117
|
-
end
|
118
|
-
|
119
|
-
def redirect_same_origin?
|
120
|
-
return false if !redirect?
|
121
|
-
uri = Addressable::URI.parse(@url).normalize
|
122
|
-
new_uri = Addressable::URI.parse(redirect_url).normalize
|
123
|
-
uri.origin == new_uri.origin
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
class HTTPError < StandardError
|
128
|
-
def initialize(obj)
|
129
|
-
@obj = obj
|
130
|
-
end
|
131
|
-
|
132
|
-
def request
|
133
|
-
@obj
|
134
|
-
end
|
135
|
-
|
136
|
-
def data
|
137
|
-
@obj.json
|
138
|
-
end
|
139
|
-
|
140
|
-
def message
|
141
|
-
"#{@obj.code}: #{@obj.body}"
|
142
|
-
end
|
143
|
-
end
|