-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve maintainability of labeler class using polymorphism
- Loading branch information
Showing
11 changed files
with
339 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
common/lib/dependabot/pull_request_creator/labelers/azure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "dependabot/pull_request_creator/labeler" | ||
|
||
module Dependabot | ||
class PullRequestCreator | ||
module Labelers | ||
class Azure < Labeler | ||
@package_manager_labels = {} | ||
|
||
# Azure does not have centralised labels | ||
def labels | ||
@labels ||= [ | ||
DEFAULT_DEPENDENCIES_LABEL, | ||
DEFAULT_SECURITY_LABEL, | ||
language_name | ||
] | ||
end | ||
|
||
def create_dependencies_label | ||
labels | ||
end | ||
|
||
def create_security_label | ||
labels | ||
end | ||
|
||
def create_language_label | ||
labels | ||
end | ||
end | ||
end | ||
end | ||
end |
77 changes: 77 additions & 0 deletions
77
common/lib/dependabot/pull_request_creator/labelers/factory.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dependabot | ||
class PullRequestCreator | ||
module Labelers | ||
class Factory | ||
class << self | ||
def for_source(source:, custom_labels:, credentials:, includes_security_fixes:, dependencies:, | ||
label_language:, automerge_candidate:) | ||
labeler_params = { | ||
custom_labels: custom_labels, | ||
includes_security_fixes: includes_security_fixes, | ||
dependencies: dependencies, | ||
label_language: label_language, | ||
automerge_candidate: automerge_candidate | ||
} | ||
|
||
case source.provider | ||
when "github" then github_labeler(source, credentials, labeler_params) | ||
when "gitlab" then gitlab_labeler(source, credentials, labeler_params) | ||
when "azure" then azure_labeler(source, labeler_params) | ||
when "bitbucket" then base_labeler(source, labeler_params) | ||
when "codecommit" then base_labeler(source, labeler_params) | ||
else raise "Unsupported provider '#{source.provider}'." | ||
end | ||
end | ||
|
||
private | ||
|
||
def github_labeler(source, credentials, labeler_params) | ||
require "dependabot/pull_request_creator/labelers/github" | ||
require "dependabot/clients/github_with_retries" | ||
client = Dependabot::Clients::GithubWithRetries.for_source( | ||
source: source, | ||
credentials: credentials | ||
) | ||
Dependabot::PullRequestCreator::Labelers::Github.new( | ||
source: source, | ||
client: client, | ||
**labeler_params | ||
) | ||
end | ||
|
||
def gitlab_labeler(source, credentials, labeler_params) | ||
require "dependabot/pull_request_creator/labelers/gitlab" | ||
require "dependabot/clients/gitlab_with_retries" | ||
client = Dependabot::Clients::GitlabWithRetries.for_source( | ||
source: source, | ||
credentials: credentials | ||
) | ||
Dependabot::PullRequestCreator::Labelers::Gitlab.new( | ||
source: source, | ||
client: client, | ||
**labeler_params | ||
) | ||
end | ||
|
||
def azure_labeler(source, labeler_params) | ||
require "dependabot/pull_request_creator/labelers/azure" | ||
Dependabot::PullRequestCreator::Labelers::Azure.new( | ||
source: source, | ||
**labeler_params | ||
) | ||
end | ||
|
||
def base_labeler(source, labeler_params) | ||
require "dependabot/pull_request_creator/labeler" | ||
Dependabot::PullRequestCreator.Labeler.new( | ||
source: source, | ||
**labeler_params | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.