Skip to content

Commit

Permalink
Replace ByTitle with ByQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
andreslucena committed Jul 15, 2024
1 parent c829d5f commit bdd28ce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/decidim/maintainers_toolbox/github_manager/querier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module GithubManager
module Querier
autoload :ByIssueId, "decidim/maintainers_toolbox/github_manager/querier/by_issue_id"
autoload :ByLabel, "decidim/maintainers_toolbox/github_manager/querier/by_label"
autoload :ByTitle, "decidim/maintainers_toolbox/github_manager/querier/by_title"
autoload :ByQuery, "decidim/maintainers_toolbox/github_manager/querier/by_query"
autoload :RelatedIssues, "decidim/maintainers_toolbox/github_manager/querier/related_issues"
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ module Querier
# Makes a GET request for the list of Issues or Pull Requests in GitHub.
#
# @param token [String] token for GitHub authentication
# @param title [String] the title that we want to search by
# @param state [String] the state of the issue. By default is "open"
# @pparam query [Hash] the query to search
#
# @see https://docs.github.com/en/rest/issues/issues#list-repository-issues GitHub API documentation
class ByTitle < Decidim::MaintainersToolbox::GithubManager::Querier::Base
def initialize(title:, token:, state: "open")
@title = title
class ByQuery < Decidim::MaintainersToolbox::GithubManager::Querier::Base
def initialize(token:, query: {})
@token = token
@state = state
@query = query
end

# Makes the GET request and parses the response of an Issue or Pull Request in GitHub
Expand All @@ -31,14 +29,12 @@ def call

private

attr_reader :title, :state
attr_reader :query

def headers
{
title: title,
state: state,
per_page: 100
}
}.merge(query)
end

# Parses the response of an Issue or Pull Request in GitHub
Expand Down
4 changes: 2 additions & 2 deletions lib/decidim/maintainers_toolbox/releaser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "open3"
require_relative "github_manager/poster"
require_relative "github_manager/querier/by_title"
require_relative "github_manager/querier/by_query"
require_relative "changelog_generator"

module Decidim
Expand Down Expand Up @@ -248,7 +248,7 @@ def run(cmd, out: $stdout)
#
# @return [Boolean] - true if there is any open PR
def pending_crowdin_pull_requests?
pull_requests = Decidim::MaintainersToolbox::GithubManager::Querier::ByTitle.new(token: @token, title: "New Crowdin updates").call
pull_requests = Decidim::MaintainersToolbox::GithubManager::Querier::ByQuery.new(token: @token, query: { title: "New Crowdin updates", creator: "decidim-bot" }).call
pull_requests.any?
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
require "decidim/maintainers_toolbox/github_manager/querier"
require "webmock/rspec"

describe Decidim::MaintainersToolbox::GithubManager::Querier::ByTitle do
let(:querier) { described_class.new(token: "abc", title: title, state: state) }
describe Decidim::MaintainersToolbox::GithubManager::Querier::ByQuery do
let(:querier) { described_class.new(token: @token, query: { title: "Fix whatever" }) }

let(:title) { "Fix whatever" }
let(:state) { "open" }

let(:stubbed_url) { "https://api.github.com/repos/decidim/decidim/issues?per_page=100&state=open&title=Fix%20whatever" }
let(:stubbed_url) { "https://api.github.com/repos/decidim/decidim/issues?per_page=100&title=Fix%20whatever" }
let(:stubbed_headers) { {} }

before do
Expand Down

0 comments on commit bdd28ce

Please sign in to comment.