Skip to content

Commit 8894738

Browse files
authored
Merge pull request #53 from github/token-env-var
Allow specifying the destination token as an environment variable.
2 parents 3346397 + 1914db5 commit 8894738

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ From a machine with access to both GitHub.com and GitHub Enterprise Server use t
2020

2121
**Required Arguments:**
2222
* `--destination-url` - The URL of the GitHub Enterprise Server instance to push the Action to.
23-
* `--destination-token` - A [Personal Access Token](https://docs.github.com/en/enterprise/user/github/authenticating-to-github/creating-a-personal-access-token) for the destination GitHub Enterprise Server instance. If the destination repository is in an organization that does not yet exist or that you are not an owner of, your token will need to have the `site_admin` scope in order to create the organization or update the repository in it. The organization can also be created manually or an existing organization that you own can be used, in which case the `repo` and `workflow` scopes are sufficient.
23+
* `--destination-token` - A [Personal Access Token](https://docs.github.com/en/enterprise/user/github/authenticating-to-github/creating-a-personal-access-token) for the destination GitHub Enterprise Server instance. If the destination repository is in an organization that does not yet exist or that you are not an owner of, your token will need to have the `site_admin` scope in order to create the organization or update the repository in it. The organization can also be created manually or an existing organization that you own can be used, in which case the `repo` and `workflow` scopes are sufficient. The token can also be provided by setting the `CODEQL_ACTION_SYNC_TOOL_DESTINATION_TOKEN` environment variable.
2424

2525
**Optional Arguments:**
2626
* `--cache-dir` - A temporary directory in which to store data downloaded from GitHub.com before it is uploaded to GitHub Enterprise Server. If not specified a directory next to the sync tool will be used.
@@ -43,7 +43,7 @@ Now use the `./codeql-action-sync push` command to upload the CodeQL Action and
4343

4444
**Required Arguments:**
4545
* `--destination-url` - The URL of the GitHub Enterprise Server instance to push the Action to.
46-
* `--destination-token` - A [Personal Access Token](https://docs.github.com/en/enterprise/user/github/authenticating-to-github/creating-a-personal-access-token) for the destination GitHub Enterprise Server instance. If the destination repository is in an organization that does not yet exist or that you are not an owner of, your token will need to have the `site_admin` scope in order to create the organization or update the repository in it. The organization can also be created manually or an existing organization that you own can be used, in which case the `repo` and `workflow` scopes are sufficient.
46+
* `--destination-token` - A [Personal Access Token](https://docs.github.com/en/enterprise/user/github/authenticating-to-github/creating-a-personal-access-token) for the destination GitHub Enterprise Server instance. If the destination repository is in an organization that does not yet exist or that you are not an owner of, your token will need to have the `site_admin` scope in order to create the organization or update the repository in it. The organization can also be created manually or an existing organization that you own can be used, in which case the `repo` and `workflow` scopes are sufficient. The token can also be provided by setting the `CODEQL_ACTION_SYNC_TOOL_DESTINATION_TOKEN` environment variable.
4747

4848
**Optional Arguments:**
4949
* `--cache-dir` - The directory to which the Action was previously downloaded.

cmd/push.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package cmd
22

33
import (
4+
"os"
5+
46
"github.com/github/codeql-action-sync/internal/cachedirectory"
7+
"github.com/github/codeql-action-sync/internal/environment"
58
"github.com/github/codeql-action-sync/internal/push"
69
"github.com/github/codeql-action-sync/internal/version"
710
"github.com/spf13/cobra"
@@ -31,8 +34,13 @@ var pushFlags = pushFlagFields{}
3134
func (f *pushFlagFields) Init(cmd *cobra.Command) {
3235
cmd.Flags().StringVar(&f.destinationURL, "destination-url", "", "The URL of the GitHub Enterprise instance to push to.")
3336
cmd.MarkFlagRequired("destination-url")
34-
cmd.Flags().StringVar(&f.destinationToken, "destination-token", "", "A token to access the API on the GitHub Enterprise instance.")
35-
cmd.MarkFlagRequired("destination-token")
37+
cmd.Flags().StringVar(&f.destinationToken, "destination-token", "", "A token to access the API on the GitHub Enterprise instance (can also be provided by setting the "+environment.DestinationToken+" environment variable).")
38+
if f.destinationToken == "" {
39+
f.destinationToken = os.Getenv(environment.DestinationToken)
40+
if f.destinationToken == "" {
41+
cmd.MarkFlagRequired("destination-token")
42+
}
43+
}
3644
cmd.Flags().StringVar(&f.destinationRepository, "destination-repository", "github/codeql-action", "The name of the repository to create on GitHub Enterprise.")
3745
cmd.Flags().StringVar(&f.actionsAdminUser, "actions-admin-user", "actions-admin", "The name of the Actions admin user.")
3846
cmd.Flags().BoolVar(&f.force, "force", false, "Replace the existing repository even if it was not created by the sync tool.")

internal/environment/environment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package environment
2+
3+
const environmentPrefix = "CODEQL_ACTION_SYNC_TOOL_"
4+
5+
const DestinationToken = environmentPrefix + "DESTINATION_TOKEN"

0 commit comments

Comments
 (0)