Skip to content

Commit 0b27887

Browse files
authored
GitHub Detector can be customized with env vars (#177)
In order for GitHub to use action for Gradle Auto Submission we need to be able to set these values on the the JSON payload submitted to our snapshots API. Added optional env var parameter: ``` GITHUB_DEPENDENCY_GRAPH_DETECTOR_NAME GITHUB_DEPENDENCY_GRAPH_DETECTOR_VERSION GITHUB_DEPENDENCY_GRAPH_DETECTOR_URL ``` These override the detector name, version and url if provided.
1 parent c1b0666 commit 0b27887

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,25 @@ This causes 2 separate plugins to be applied, that can be used independently:
2828
- `GitHubDependencyExtractorPlugin` collects all dependencies that are resolved during a build execution and writes these to a file. The output file can be found at `<root>/build/reports/github-depenency-graph-snapshots/<job-correlator>.json`.
2929
- `ForceDependencyResolutionPlugin` creates a `ForceDependencyResolutionPlugin_resolveAllDependencies` task that will attempt to resolve all dependencies for a Gradle build, by simply invoking `dependencies` on all projects.
3030

31-
### Required environment variables
31+
### Environment variables
3232

3333
The following environment variables configure the snapshot generated by the `GitHubDependencyExtractorPlugin`. See the [GitHub Dependency Submission API docs](https://docs.github.com/en/rest/dependency-graph/dependency-submission?apiVersion=2022-11-28) for details:
34+
35+
#### Required environment variables
36+
3437
- `GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR`: Sets the `job.correlator` value for the dependency submission
3538
- `GITHUB_DEPENDENCY_GRAPH_JOB_ID`: Sets the `job.id` value for the dependency submission
3639
- `GITHUB_DEPENDENCY_GRAPH_REF`: Sets the `ref` value for the commit that generated the dependency graph
3740
- `GITHUB_DEPENDENCY_GRAPH_SHA`: Sets the `sha` value for the commit that generated the dependency graph
3841
- `GITHUB_DEPENDENCY_GRAPH_WORKSPACE`: Sets the root directory of the github repository. Must be an absolute path.
3942
- `DEPENDENCY_GRAPH_REPORT_DIR` (optional): Specifies where the dependency graph report will be generated. Must be an absolute path.
4043

44+
#### Optional environment variables
45+
46+
- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_NAME`: Sets the `detector.name` value for the dependency submission. Defaults to `GitHub Dependency Graph Gradle Plugin`
47+
- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_VERSION`: Sets the `detector.version` value for the dependency submission. Defaults to current version of the plugin.
48+
- `GITHUB_DEPENDENCY_GRAPH_DETECTOR_URL`: Sets the `detector.url` value for the dependency submission. Defaults to `https://github.com/gradle/github-dependency-graph-gradle-plugin`
49+
4150
Each of these values can also be provided via a system property.
4251
eg: Env var `DEPENDENCY_GRAPH_REPORT_DIR` can be set with `-DDEPENDENCY_GRAPH_REPORT_DIR=...` on the command-line.
4352

plugin/src/main/kotlin/org/gradle/github/dependencygraph/GitHubRepositorySnapshotBuilder.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ class GitHubRepositorySnapshotBuilder(
1010
private val snapshotParams: GitHubSnapshotParams
1111
) {
1212

13-
private val detector by lazy { GitHubDetector() }
13+
private val detector by lazy {
14+
GitHubDetector(
15+
name = snapshotParams.githubDetectorName,
16+
version = snapshotParams.githubDetectorVersion,
17+
url = snapshotParams.githubDetectorUrl
18+
)
19+
}
1420

1521
private val job by lazy {
1622
GitHubJob(

plugin/src/main/kotlin/org/gradle/github/dependencygraph/GitHubSnapshotParams.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const val PARAM_JOB_ID = "GITHUB_DEPENDENCY_GRAPH_JOB_ID"
88
const val PARAM_JOB_CORRELATOR = "GITHUB_DEPENDENCY_GRAPH_JOB_CORRELATOR"
99
const val PARAM_GITHUB_REF = "GITHUB_DEPENDENCY_GRAPH_REF"
1010
const val PARAM_GITHUB_SHA = "GITHUB_DEPENDENCY_GRAPH_SHA"
11+
const val PARAM_GITHUB_DETECTOR_NAME = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_NAME"
12+
const val PARAM_GITHUB_DETECTOR_VERSION = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_VERSION"
13+
const val PARAM_GITHUB_DETECTOR_URL = "GITHUB_DEPENDENCY_GRAPH_DETECTOR_URL"
1114
/**
1215
* Environment variable should be set to the workspace directory that the Git repository is checked out in.
1316
* This is used to determine relative path to build files referenced in the dependency graph.
@@ -16,9 +19,15 @@ const val PARAM_GITHUB_WORKSPACE = "GITHUB_DEPENDENCY_GRAPH_WORKSPACE"
1619

1720
class GitHubSnapshotParams(pluginParameters: PluginParameters) {
1821
val dependencyGraphJobCorrelator: String = pluginParameters.load(PARAM_JOB_CORRELATOR)
19-
val dependencyGraphJobId: String =pluginParameters.load(PARAM_JOB_ID)
22+
val dependencyGraphJobId: String = pluginParameters.load(PARAM_JOB_ID)
2023
val gitSha: String = pluginParameters.load(PARAM_GITHUB_SHA)
2124
val gitRef: String = pluginParameters.load(PARAM_GITHUB_REF)
2225
val gitHubWorkspace: Path = Paths.get(pluginParameters.load(PARAM_GITHUB_WORKSPACE))
26+
val githubDetectorName: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_NAME)
27+
?: javaClass.`package`.implementationTitle
28+
val githubDetectorVersion: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_VERSION)
29+
?: javaClass.`package`.implementationVersion
30+
val githubDetectorUrl: String = pluginParameters.loadOptional(PARAM_GITHUB_DETECTOR_URL)
31+
?: "https://github.com/gradle/github-dependency-graph-gradle-plugin"
2332
}
2433

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.gradle.github.dependencygraph.model
22

33
data class GitHubDetector(
4-
val name: String = GitHubDetector::class.java.`package`.implementationTitle,
5-
val version: String = GitHubDetector::class.java.`package`.implementationVersion,
6-
val url: String = "https://github.com/gradle/github-dependency-graph-gradle-plugin"
4+
val name: String,
5+
val version: String,
6+
val url: String
77
)

0 commit comments

Comments
 (0)