-
Notifications
You must be signed in to change notification settings - Fork 3
Add a method to bypass GitHub API #255
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,43 +14,52 @@ pub struct GitContext { | |||||||||||||||||||||||||||
| impl GitContext { | ||||||||||||||||||||||||||||
| pub fn from_cli_and_github( | ||||||||||||||||||||||||||||
| cli: &FlakeHubPushCli, | ||||||||||||||||||||||||||||
| github_graphql_data_result: &GithubGraphqlDataResult, | ||||||||||||||||||||||||||||
| github_graphql_data_result: Option<GithubGraphqlDataResult>, | ||||||||||||||||||||||||||||
| ) -> Result<Self> { | ||||||||||||||||||||||||||||
| // step: validate spdx, backfill from GitHub API | ||||||||||||||||||||||||||||
| let spdx_expression = if cli.spdx_expression.0.is_none() { | ||||||||||||||||||||||||||||
| if let Some(spdx_string) = &github_graphql_data_result.spdx_identifier { | ||||||||||||||||||||||||||||
| if let Some(spdx_string) = github_graphql_data_result | ||||||||||||||||||||||||||||
| .clone() | ||||||||||||||||||||||||||||
| .and_then(|result| result.spdx_identifier.clone()) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| tracing::debug!("Recieved SPDX identifier `{}` from GitHub API", spdx_string); | ||||||||||||||||||||||||||||
| let parsed = spdx::Expression::parse(spdx_string) | ||||||||||||||||||||||||||||
| let parsed = spdx::Expression::parse(&spdx_string) | ||||||||||||||||||||||||||||
| .wrap_err("Invalid SPDX license identifier reported from the GitHub API, either you are using a non-standard license or GitHub has returned a value that cannot be validated")?; | ||||||||||||||||||||||||||||
| Some(parsed) | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| None | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| // Provide the user notice if the SPDX expression passed differs from the one detected on GitHub -- It's probably something they care about. | ||||||||||||||||||||||||||||
| if github_graphql_data_result.spdx_identifier | ||||||||||||||||||||||||||||
| != cli.spdx_expression.0.as_ref().map(|v| v.to_string()) | ||||||||||||||||||||||||||||
| if github_graphql_data_result | ||||||||||||||||||||||||||||
| .clone() | ||||||||||||||||||||||||||||
| .map(|result| result.spdx_identifier) | ||||||||||||||||||||||||||||
| != Some(cli.spdx_expression.0.as_ref().map(|v| v.to_string())) | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| tracing::warn!( | ||||||||||||||||||||||||||||
| "SPDX identifier `{}` was passed via argument, but GitHub's API suggests it may be `{}`", | ||||||||||||||||||||||||||||
| cli.spdx_expression.0.as_ref().map(|v| v.to_string()).unwrap_or_else(|| "None".to_string()), | ||||||||||||||||||||||||||||
| github_graphql_data_result.spdx_identifier.clone().unwrap_or_else(|| "None".to_string()), | ||||||||||||||||||||||||||||
| github_graphql_data_result.clone().map(|result| result.spdx_identifier.clone().unwrap_or_else(|| "None".to_string())).unwrap_or_else(|| "None".to_string()), | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| cli.spdx_expression.0.clone() | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let rev = cli | ||||||||||||||||||||||||||||
| .rev | ||||||||||||||||||||||||||||
| .0 | ||||||||||||||||||||||||||||
| .as_ref() | ||||||||||||||||||||||||||||
| .unwrap_or(&github_graphql_data_result.revision); | ||||||||||||||||||||||||||||
| let rev = cli.rev.0.clone().unwrap_or_else(|| { | ||||||||||||||||||||||||||||
| github_graphql_data_result | ||||||||||||||||||||||||||||
| .clone() | ||||||||||||||||||||||||||||
| .expect("GitHub API is disabled and rev is not specified") | ||||||||||||||||||||||||||||
| .revision | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
Comment on lines
+48
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace panic with proper error handling. Using Apply this diff: - let rev = cli.rev.0.clone().unwrap_or_else(|| {
- github_graphql_data_result
- .clone()
- .expect("GitHub API is disabled and rev is not specified")
- .revision
- });
+ let rev = match cli.rev.0.clone() {
+ Some(r) => r,
+ None => github_graphql_data_result
+ .clone()
+ .ok_or_else(|| eyre!("Could not determine revision: GitHub API is disabled and --rev was not specified"))?
+ .revision,
+ };📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let ctx = GitContext { | ||||||||||||||||||||||||||||
| spdx_expression, | ||||||||||||||||||||||||||||
| repo_topics: github_graphql_data_result.topics.clone(), | ||||||||||||||||||||||||||||
| repo_topics: github_graphql_data_result | ||||||||||||||||||||||||||||
| .clone() | ||||||||||||||||||||||||||||
| .map(|result| result.topics.clone()) | ||||||||||||||||||||||||||||
| .unwrap_or_default(), | ||||||||||||||||||||||||||||
| revision_info: RevisionInfo { | ||||||||||||||||||||||||||||
| commit_count: Some(github_graphql_data_result.rev_count as usize), | ||||||||||||||||||||||||||||
| commit_count: github_graphql_data_result.map(|result| result.rev_count as usize), | ||||||||||||||||||||||||||||
| revision: rev.to_string(), | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ type ExecutionEnvironment = { | |
| FLAKEHUB_PUSH_ROLLING?: string; | ||
| FLAKEHUB_PUSH_MIRROR?: string; | ||
| FLAKEHUB_PUSH_ROLLING_MINOR?: string; | ||
| FLAKEHUB_PUSH_DISABLE_GITHUB_API?: string; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they're using the GitHub Action, why would we want to disable the GitHub API?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| GITHUB_CONTEXT?: string; | ||
| }; | ||
|
|
||
|
|
@@ -50,6 +51,7 @@ class FlakeHubPushAction extends DetSysAction { | |
| private mirror: boolean; | ||
| private name: string | null; | ||
| private rollingMinor: number | null; | ||
| private disableGitHubAPI: boolean; | ||
|
|
||
| constructor() { | ||
| super({ | ||
|
|
@@ -79,6 +81,7 @@ class FlakeHubPushAction extends DetSysAction { | |
| this.mirror = inputs.getBool("mirror"); | ||
| this.name = inputs.getStringOrNull("name"); | ||
| this.rollingMinor = inputs.getNumberOrNull("rolling-minor"); | ||
| this.disableGitHubAPI = inputs.getBool("disable-github-api"); | ||
| } | ||
|
|
||
| async main(): Promise<void> { | ||
|
|
@@ -133,6 +136,7 @@ class FlakeHubPushAction extends DetSysAction { | |
| env.FLAKEHUB_PUSH_INCLUDE_OUTPUT_PATHS = this.includeOutputPaths.toString(); | ||
| env.FLAKEHUB_PUSH_ROLLING = this.rolling.toString(); | ||
| env.FLAKEHUB_PUSH_MIRROR = this.mirror.toString(); | ||
| env.FLAKEHUB_PUSH_DISABLE_GITHUB_API = this.disableGitHubAPI.toString(); | ||
|
|
||
| env.GITHUB_CONTEXT = JSON.stringify(actionsGithub.context); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably just make another function that doesn't accept
GithubGraphqlDataResultas an arg instead of making this optional. The function isfrom_cli_and_github, notfrom_cli_and_maybe_github_if_reasons;P