-
Notifications
You must be signed in to change notification settings - Fork 606
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
Support GitHub Actions Badges #1838
Changes from 10 commits
0fbcbaa
a9dfee9
7c423ed
eed02e1
31d83c3
9e458d6
5c5f505
0daadf0
73f033d
f136c52
4d55e2d
3956277
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<a href="{{ this.url }}"> | ||
<img src="{{ this.imageUrl }}" alt="{{ this.text }}" title="{{ this.text }}"> | ||
|
||
</a> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||
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_enc,branch,event}', function() { | ||||||
const url = new URL(`https://github.com/${this.repository}/actions`); | ||||||
|
||||||
if (this.workflow_enc !== '') { | ||||||
url.searchParams.set('workflow', this.workflow_enc); | ||||||
} | ||||||
|
||||||
if (this.branch !== '') { | ||||||
url.searchParams.set('branch', this.branch); | ||||||
} | ||||||
|
||||||
if (this.event !== '') { | ||||||
url.searchParams.set('event', this.event); | ||||||
} | ||||||
|
||||||
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 encodeURIComponent(this.get('badge.attributes.branch') || 'master'); | ||||||
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.
Suggested change
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. I think we want to encode branch names, for branches with 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. Ah wait, 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. Branch names do need to be encoded, but |
||||||
}), | ||||||
event: computed('badge.attributes.event', function() { | ||||||
return encodeURIComponent(this.get('badge.attributes.event') || ''); | ||||||
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.
Suggested change
|
||||||
}), | ||||||
text: computed('badge', function() { | ||||||
return `GitHub Actions workflow status for the ${this.workflow} workflow on the ${this.branch} branch`; | ||||||
}), | ||||||
}); |
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.
It looks like this’ll double-encode the workflow.
(and the condition too for neatness even though it behaves the same)
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.
According to this doc
url.searchParams
isreadOnly
. Are you sure, that it can be used like this? (I'm a JS noob, so maybe my understanding is completely wrong)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.
The property is read-only:
but its value, the
URLSearchParams
, isn’t.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.
I just tested this and the format produced by the
searchParams
isn't accepted by GitHub. We need this format:query=workflow%3A"Say+hello%2Fwhatever"+branch%3Abadges-test+event%3Apush