-
Notifications
You must be signed in to change notification settings - Fork 643
Support GitHub Actions Badges #1838
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0fbcbaa
Support GitHub Actions Badges
CryZe a9dfee9
Escape whitespace
CryZe 7c423ed
Implement `event` and `branch` attributes
CryZe eed02e1
Apply fixes from rebase
CryZe 31d83c3
Fix Formatting
CryZe 9e458d6
Use URL to build imageURL query
flip1995 5c5f505
Fix rebase fallout
flip1995 0daadf0
Use unencoded workflow name as (alt-)text
flip1995 73f033d
Use query URL for badge link
flip1995 f136c52
Also show branch name in the (alt-)text
flip1995 4d55e2d
Fix building of url
flip1995 3956277
Don't encode branch and event name
flip1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<a href="{{ this.url }}"> | ||
<img src="{{ this.imageUrl }}" alt="{{ this.text }}" title="{{ this.text }}"> | ||
|
||
</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Component from '@ember/component'; | ||
import { computed } from '@ember/object'; | ||
import { alias } from '@ember/object/computed'; | ||
|
||
export default Component.extend({ | ||
tagName: 'span', | ||
repository: alias('badge.attributes.repository'), | ||
imageUrl: computed('badge.attributes.{repository,workflow_enc,branch,event}', function() { | ||
const url = new URL(`https://github.com/${this.repository}/workflows/${this.workflow_enc}/badge.svg`); | ||
|
||
if (this.branch !== '') { | ||
url.searchParams.set('branch', this.branch); | ||
} | ||
|
||
if (this.event !== '') { | ||
url.searchParams.set('event', this.event); | ||
} | ||
|
||
return url.href; | ||
}), | ||
url: computed('badge.attributes.{repository,workflow,branch,event}', function() { | ||
const url = new URL(`https://github.com/${this.repository}/actions`); | ||
|
||
let query = ''; | ||
if (this.workflow !== '') { | ||
query += `workflow:"${this.workflow}"`; | ||
} | ||
|
||
if (this.branch !== '') { | ||
query += `branch:"${this.branch}"`; | ||
} | ||
|
||
if (this.event !== '') { | ||
query += `event:"${this.event}"`; | ||
} | ||
|
||
if (query !== '') { | ||
url.searchParams.set('query', query); | ||
} | ||
|
||
return url.href; | ||
}), | ||
workflow: computed('badge.attributes.workflow', function() { | ||
return this.get('badge.attributes.workflow'); | ||
}), | ||
workflow_enc: computed('badge.attributes.workflow', function() { | ||
return this.get('badge.attributes.workflow') | ||
.split('/') | ||
.map(encodeURIComponent) | ||
.join('/'); | ||
}), | ||
branch: computed('badge.attributes.branch', function() { | ||
return this.get('badge.attributes.branch') || 'master'; | ||
}), | ||
event: computed('badge.attributes.event', function() { | ||
return this.get('badge.attributes.event') || ''; | ||
}), | ||
text: computed('badge', function() { | ||
return `GitHub Actions workflow status for the ${this.workflow} workflow on the ${this.branch} branch`; | ||
}), | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For anyone who might have been wondering: quotes can be escaped as
\"
, but there doesn’t seem to be a way to represent a query where multiple quoted terms end with a backslash. Because out of these three, only workflow names can end with backslashes, it is possible to support every workflow name by:workflow:
part lastI’m sure trailing backslashes aren’t considered important enough to support here, but how about ASCII double quotes in workflow and branch names?