Skip to content

Commit

Permalink
warn on state retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
yazgoo committed Jun 25, 2024
1 parent 16c8d46 commit 7366314
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ object AnalyzeDependencyGraph {
private def highlight(string: String, pattern: String): String =
string.replaceAll(pattern, s"\u001b[32m${pattern}\u001b[0m")

private def getStateOrWarn[T](state: State, key: AttributeKey[T], what: String, command: String): Option[T] =
state.get(key).orElse {
println(s"🟠 No $what found, please run '$command' first")
None
}

private def getGithubManifest(state: State): Seq[Map[String, Manifest]] =
getStateOrWarn(state, githubManifestsKey, "dependencies", SubmitDependencyGraph.Generate).toSeq

private def analyzeDependenciesInternal(
state: State,
action: AnalysisAction,
Expand Down Expand Up @@ -135,9 +144,7 @@ object AnalyzeDependencyGraph {
}
}

val matches = state
.get(githubManifestsKey)
.toSeq
val matches = getGithubManifest(state)
.flatMap { manifests =>
manifests.map {
case (name, manifest) =>
Expand Down Expand Up @@ -193,9 +200,7 @@ object AnalyzeDependencyGraph {
}

private def getAllArtifacts(state: State): Seq[String] =
state
.get(githubManifestsKey)
.toSeq
getGithubManifest(state)
.flatMap { manifests =>
manifests.flatMap {
case (_, manifest) =>
Expand Down Expand Up @@ -231,7 +236,7 @@ object AnalyzeDependencyGraph {
}

private def analyzeCves(state: State): State = {
val vulnerabilities = state.get(githubAlertsKey).getOrElse(Seq.empty)
val vulnerabilities = getStateOrWarn(state, githubAlertsKey, "artifcats", s"${AnalyzeDependencies} alerts").getOrElse(Seq.empty)
val artifacts = getAllArtifacts(state)
vulnerabilities.foreach { v =>
val matches = vulnerabilityMatchesArtifacts(v, artifacts)
Expand Down Expand Up @@ -298,5 +303,5 @@ object AnalyzeDependencyGraph {
}
}

private def githubToken(): String = Properties.envOrElse("GITHUB_TOKEN", "")
private def githubToken( ): String = Properties.envOrElse("GITHUB_TOKEN", "")
}

0 comments on commit 7366314

Please sign in to comment.