Skip to content

Commit d85627c

Browse files
committed
1 parent 6f5e217 commit d85627c

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Component from '@ember/component';
2+
import { computed } from '@ember/object';
3+
import { alias } from '@ember/object/computed';
4+
5+
export default Component.extend({
6+
tagName: 'span',
7+
classNames: ['badge'],
8+
repository: alias('badge.attributes.repository'),
9+
workflow: alias('badge.attributes.workflow'),
10+
text: computed('badge', function() {
11+
return `GitHub Actions workflow status for the ${this.workflow} workflow`;
12+
}),
13+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<a href="https://github.com/{{ repository }}/actions">
2+
<img
3+
src="https://github.com/{{ repository }}/workflows/{{ workflow }}/badge.svg"
4+
alt="{{ text }}"
5+
title="{{ text }}">
6+
</a>

src/models/badge.rs

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub enum Badge {
3939
pipeline: String,
4040
build: Option<String>,
4141
},
42+
#[serde(rename = "github-actions")]
43+
GitHubActions {
44+
repository: String,
45+
workflow: String,
46+
},
4247
#[serde(rename = "gitlab")]
4348
GitLab {
4449
repository: String,

src/tests/badge.rs

+67
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ struct BadgeRef {
77
appveyor_attributes: HashMap<String, String>,
88
travis_ci: Badge,
99
travis_ci_attributes: HashMap<String, String>,
10+
github_actions: Badge,
11+
github_actions_attributes: HashMap<String, String>,
1012
gitlab: Badge,
1113
gitlab_attributes: HashMap<String, String>,
1214
azure_devops: Badge,
@@ -76,6 +78,15 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
7678
badge_attributes_travis_ci.insert(String::from("branch"), String::from("beta"));
7779
badge_attributes_travis_ci.insert(String::from("repository"), String::from("rust-lang/rust"));
7880

81+
let github_actions = Badge::GitHubActions {
82+
repository: String::from("rust-lang/rust"),
83+
workflow: String::from("build"),
84+
};
85+
let mut badge_attributes_github_actions = HashMap::new();
86+
badge_attributes_github_actions
87+
.insert(String::from("repository"), String::from("rust-lang/rust"));
88+
badge_attributes_github_actions.insert(String::from("workflow"), String::from("build"));
89+
7990
let gitlab = Badge::GitLab {
8091
branch: Some(String::from("beta")),
8192
repository: String::from("rust-lang/rust"),
@@ -158,6 +169,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
158169
appveyor_attributes: badge_attributes_appveyor,
159170
travis_ci,
160171
travis_ci_attributes: badge_attributes_travis_ci,
172+
github_actions,
173+
github_actions_attributes: badge_attributes_github_actions,
161174
gitlab,
162175
gitlab_attributes: badge_attributes_gitlab,
163176
azure_devops,
@@ -213,6 +226,20 @@ fn update_add_travis_ci() {
213226
assert_eq!(krate.badges(), vec![test_badges.travis_ci]);
214227
}
215228

229+
#[test]
230+
fn update_add_github_actions() {
231+
// Add a github actions badge
232+
let (krate, test_badges) = set_up();
233+
234+
let mut badges = HashMap::new();
235+
badges.insert(
236+
String::from("github-actions"),
237+
test_badges.github_actions_attributes,
238+
);
239+
krate.update(&badges);
240+
assert_eq!(krate.badges(), vec![test_badges.github_actions]);
241+
}
242+
216243
#[test]
217244
fn update_add_gitlab() {
218245
// Add a gitlab badge
@@ -432,6 +459,46 @@ fn travis_ci_required_keys() {
432459
assert_eq!(krate.badges(), vec![]);
433460
}
434461

462+
#[test]
463+
fn github_actions_required_key_repository() {
464+
// Add a GitHub Actions badge missing the required repository field
465+
let (krate, mut test_badges) = set_up();
466+
467+
let mut badges = HashMap::new();
468+
469+
// Repository is a required key
470+
test_badges.github_actions_attributes.remove("repository");
471+
badges.insert(
472+
String::from("github-actions"),
473+
test_badges.github_actions_attributes,
474+
);
475+
476+
let invalid_badges = krate.update(&badges);
477+
assert_eq!(invalid_badges.len(), 1);
478+
assert_eq!(invalid_badges.first().unwrap(), "github-actions");
479+
assert_eq!(krate.badges(), vec![]);
480+
}
481+
482+
#[test]
483+
fn github_actions_required_key_workflow() {
484+
// Add a GitHub Actions badge missing the required workflow field
485+
let (krate, mut test_badges) = set_up();
486+
487+
let mut badges = HashMap::new();
488+
489+
// Workflow is a required key
490+
test_badges.github_actions_attributes.remove("workflow");
491+
badges.insert(
492+
String::from("github-actions"),
493+
test_badges.github_actions_attributes,
494+
);
495+
496+
let invalid_badges = krate.update(&badges);
497+
assert_eq!(invalid_badges.len(), 1);
498+
assert_eq!(invalid_badges.first().unwrap(), "github-actions");
499+
assert_eq!(krate.badges(), vec![]);
500+
}
501+
435502
#[test]
436503
fn gitlab_required_keys() {
437504
// Add a gitlab badge missing a required field

0 commit comments

Comments
 (0)