From 315da90462344dd15ba1db83556c551d6ef5e865 Mon Sep 17 00:00:00 2001 From: Evgeny Chukreev Date: Tue, 17 Jan 2023 14:55:09 +0100 Subject: [PATCH] Add credentials via environment variable. --- README.md | 8 ++++++++ generic-update-script.rb | 17 +++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b3793d5d..c1707e19 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,14 @@ 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 +`CREDENTIALS` | `[]` | JSON array containing credentials that can be used to specify what additional resources Dependabot can access and how it can access them. + +The content of both the OPTIONS and CREDENTIALS variables depend on the selected package manager. For example, when using "maven", the CREDENTIALS variable can be used to specify an +additional repository or to completely replace the default maven central repository with a custom one: + +```shell +export CREDENTIALS='[{"type": "maven_repository", "url": "https://example.com/maven", "replaces-base": true}]' +``` There are other variables that you must pass to your container that will depend on the Git source you use: diff --git a/generic-update-script.rb b/generic-update-script.rb index 147fd894..de01cead 100644 --- a/generic-update-script.rb +++ b/generic-update-script.rb @@ -10,14 +10,15 @@ require "gitlab" require "json" -credentials = [ - { - "type" => "git_source", - "host" => "github.com", - "username" => "x-access-token", - "password" => ENV["GITHUB_ACCESS_TOKEN"] # A GitHub access token with read access to public repos - } -] +# Get optional credentials from the environment variable called CREDENTIALS (json array). +credentials = JSON.parse(ENV["CREDENTIALS"] || "[]") + +credentials << { + "type" => "git_source", + "host" => "github.com", + "username" => "x-access-token", + "password" => ENV["GITHUB_ACCESS_TOKEN"] # A GitHub access token with read access to public repos +} # Full name of the repo you want to create pull requests for. repo_name = ENV["PROJECT_PATH"] # namespace/project