Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuration files #888

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Variable Name | Default | Notes
`BRANCH ` | N/A (Optional) | Branch to fetch manifest from and open pull requests against.
`PULL_REQUESTS_ASSIGNEE` | N/A (Optional) | User to assign to the created pull request.
`OPTIONS` | `{}` | JSON options to customize the operation of Dependabot
`USE_CONFIG` | `false` | Whether to use dependabot.yml configuration file. Valid values are `true` and `false`.

There are other variables that you must pass to your container that will depend on the Git source you use:

Expand Down
32 changes: 31 additions & 1 deletion generic-update-script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
require "dependabot/omnibus"
require "gitlab"
require "json"
require "dependabot/file_fetchers"
require "dependabot/config/file_fetcher"


$stdout.sync = true

credentials = [
{
Expand All @@ -28,6 +33,8 @@
# Branch to look at. Defaults to repo's default branch
branch = ENV["BRANCH"]

use_config = (ENV["USE_CONFIG"] || "false").downcase == 'true'

# Name of the package manager you'd like to do the update for. Options are:
# - bundler
# - pip (includes pipenv)
Expand Down Expand Up @@ -147,6 +154,27 @@
)
end

################################
# Fetch the configuration file #
################################
if use_config
config = Dependabot::Config::FileFetcher.new(
source: source,
credentials: credentials,
options: options,
).config_file

puts "","Read the following config from '#{repo_name}':\n",config.content,""

config = Dependabot::Config::File.parse(config.content)
config = config.update_config(
package_manager,
directory: directory,
)
else
config = nil
end

##############################
# Fetch the dependency files #
##############################
Expand Down Expand Up @@ -181,6 +209,7 @@
dependency: dep,
dependency_files: files,
credentials: credentials,
ignored_versions: config ? config.ignored_versions_for(dep) : [],
options: options,
)

Expand Down Expand Up @@ -218,7 +247,8 @@
########################################
# Create a pull request for the update #
########################################
assignee = (ENV["PULL_REQUESTS_ASSIGNEE"] || ENV["GITLAB_ASSIGNEE_ID"])&.to_i
assignee = (ENV["PULL_REQUESTS_ASSIGNEE"] || ENV["GITLAB_ASSIGNEE_ID"])
assignee = assignee&.to_i.to_s == assignee ? assignee&.to_i : assignee
assignees = assignee ? [assignee] : assignee
pr_creator = Dependabot::PullRequestCreator.new(
source: source,
Expand Down