Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions content/patterns/rhoso-gitops/_index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ industries:
focus_areas:
- DevSecOps
aliases: /rhoso-gitops/
ci: rhoso-gitops
ci_github_sources:
- raw_base: https://raw.githubusercontent.com/validatedpatterns-sandbox/rhoso-gitops/reporting/
files:
- rhoso-gitops-baremetal-4.18-stable-badge.json
links:
github: https://github.com/validatedpatterns-sandbox/rhoso-gitops
install: getting-started
Expand Down
10 changes: 9 additions & 1 deletion layouts/ci/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ <h1>{{- .Title -}}</h1>
</div>
<script>
{{ $internal := .Param "internal" }}
obtainBadges({ 'target': 'ci-dataset' {{ if (eq $internal true ) }}, 'links': 'internal'{{ end }} });
{{ $githubSources := slice }}
{{ range .Site.Pages }}
{{ if ne .Params.tier "archived" }}
{{ range .Params.ci_github_sources }}
{{ $githubSources = $githubSources | append . }}
{{ end }}
{{ end }}
{{ end }}
obtainBadges({ 'target': 'ci-dataset', 'github_sources': {{ $githubSources | jsonify | safeJS }} {{ if (eq $internal true ) }}, 'links': 'internal'{{ end }} });
</script>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/ci.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
{{ partial "spinner.html" . }}
</div>
<script>
obtainBadges({ 'target':'ci-dataset', 'filter_field':'pattern', 'filter_value': '{{ .Params.ci }}', 'disable_buttons': true });
obtainBadges({ 'target':'ci-dataset', 'filter_field':'pattern', 'filter_value': '{{ .Params.ci }}', 'disable_buttons': true, 'github_sources': {{ .Params.ci_github_sources | default (slice) | jsonify | safeJS }} });
</script>
</div>
41 changes: 38 additions & 3 deletions static/js/dashboard.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

class Badge {

constructor(base, key, date) {
constructor(base, key, date, useJsonMetadata = false) {
this.base = base
this.key = key
this._json = null
this.useJsonMetadata = useJsonMetadata || isNewCiBadgeBase(base)
this.operator = 'N/A'
this.date = date.substr(0, 10)
this.pattern = ''
this.platform = ''
this.version = ''

if (isNewCiBadgeBase(base)) {
if (this.useJsonMetadata) {
return
}

Expand All @@ -36,7 +37,7 @@ class Badge {
applyJson(json) {
this._json = json

if (!isNewCiBadgeBase(this.base)) {
if (!this.useJsonMetadata) {
return this
}

Expand Down Expand Up @@ -410,6 +411,9 @@ function enrichBadgesFromJson(badges) {
return Promise.resolve(badges || [])
}
return Promise.all(badges.map(function (badge) {
if (badge._json != null) {
return Promise.resolve(badge)
}
return fetch(badge.getURI())
.then(function (response) {
if (!response.ok) {
Expand Down Expand Up @@ -1401,6 +1405,34 @@ function fetchBucketBadges(bucket, inputs) {
})
}

function fetchGithubBadges(source, badgeSet) {
const base = source.raw_base.replace(/\/$/, '')
const files = source.files.filter(function (key) {
return (badgeSet === 'GA' && key.endsWith('stable-badge.json')) ||
(badgeSet === 'early' && (key.endsWith('prerelease-badge.json') ||
key.endsWith('nightly-badge.json') || key.endsWith('operator-badge.json'))) ||
(badgeSet === 'all' && key.endsWith('-badge.json'))
})
return Promise.all(files.map(function (key) {
return fetch(base + '/' + key)
.then(function (response) {
if (!response.ok) {
throw new Error('HTTP error: ' + response.status)
}
return response.json()
})
.then(function (json) {
return new Badge(base, key, json.date || '', true).applyJson(json)
})
.catch(function (error) {
console.warn('GitHub CI badge unavailable:', key, error.message)
return null
})
})).then(function (badges) {
return badges.filter(function (badge) { return badge != null })
})
}

function obtainBadgesFromSample(inputs) {
const options = getBucketOptions(inputs);

Expand Down Expand Up @@ -1440,6 +1472,9 @@ function obtainBadges(inputs) {
for (const bucket of buckets) {
badgePromises.push(fetchBucketBadges(bucket, inputs));
}
for (const source of inputs.github_sources || []) {
badgePromises.push(fetchGithubBadges(source, options.get('sets')))
}

Promise.all(badgePromises)
.then(function (results) {
Expand Down
Loading