Support version transformation for GitHub tags
This commit is contained in:
parent
6e313e2272
commit
d63e657948
@ -24,7 +24,7 @@ module SlackBuilder
|
||||
GITHUB_QUERY = <<~GQL
|
||||
query ($name: String!, $owner: String!) {
|
||||
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 {
|
||||
id,
|
||||
name
|
||||
@ -35,11 +35,12 @@ module SlackBuilder
|
||||
GQL
|
||||
private_constant :GITHUB_QUERY
|
||||
|
||||
def initialize(owner, name)
|
||||
def initialize(owner, name, version_transform = ->(x) { x })
|
||||
super()
|
||||
|
||||
@owner = owner
|
||||
@name = name
|
||||
@version_transform = version_transform
|
||||
end
|
||||
|
||||
def latest
|
||||
@ -52,7 +53,16 @@ module SlackBuilder
|
||||
'content-type' => 'application/json',
|
||||
'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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user