Support version transformation for GitHub tags
This commit is contained in:
parent
6e313e2272
commit
d63e657948
@ -24,7 +24,7 @@ module SlackBuilder
|
|||||||
GITHUB_QUERY = <<~GQL
|
GITHUB_QUERY = <<~GQL
|
||||||
query ($name: String!, $owner: String!) {
|
query ($name: String!, $owner: String!) {
|
||||||
repository(name: $name, owner: $owner) {
|
repository(name: $name, owner: $owner) {
|
||||||
refs(last: 1, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
|
refs(last: 10, refPrefix: "refs/tags/", orderBy: { field: TAG_COMMIT_DATE, direction: ASC }) {
|
||||||
nodes {
|
nodes {
|
||||||
id,
|
id,
|
||||||
name
|
name
|
||||||
@ -35,11 +35,12 @@ module SlackBuilder
|
|||||||
GQL
|
GQL
|
||||||
private_constant :GITHUB_QUERY
|
private_constant :GITHUB_QUERY
|
||||||
|
|
||||||
def initialize(owner, name)
|
def initialize(owner, name, version_transform = ->(x) { x })
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@owner = owner
|
@owner = owner
|
||||||
@name = name
|
@name = name
|
||||||
|
@version_transform = version_transform
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest
|
def latest
|
||||||
@ -52,7 +53,16 @@ module SlackBuilder
|
|||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'authorization' => "Bearer #{CONFIG[:gh_token]}"
|
'authorization' => "Bearer #{CONFIG[:gh_token]}"
|
||||||
}
|
}
|
||||||
JSON.parse(response.body)['data']['repository']['refs']['nodes'].first['name']
|
filter_versions_from_response JSON.parse(response.body)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def filter_versions_from_response(response)
|
||||||
|
response['data']['repository']['refs']['nodes']
|
||||||
|
.map { |node| @version_transform.call node['name'] }
|
||||||
|
.compact
|
||||||
|
.last
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user