Skip to content

Commit 8430e65

Browse files
committed
1 parent 6f5e217 commit 8430e65

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-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

+57
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,14 @@ 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.insert(String::from("repository"), String::from("rust-lang/rust"));
87+
badge_attributes_github_actions.insert(String::from("workflow"), String::from("build"));
88+
7989
let gitlab = Badge::GitLab {
8090
branch: Some(String::from("beta")),
8191
repository: String::from("rust-lang/rust"),
@@ -158,6 +168,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
158168
appveyor_attributes: badge_attributes_appveyor,
159169
travis_ci,
160170
travis_ci_attributes: badge_attributes_travis_ci,
171+
github_actions,
172+
github_actions_attributes: badge_attributes_github_actions,
161173
gitlab,
162174
gitlab_attributes: badge_attributes_gitlab,
163175
azure_devops,
@@ -213,6 +225,17 @@ fn update_add_travis_ci() {
213225
assert_eq!(krate.badges(), vec![test_badges.travis_ci]);
214226
}
215227

228+
#[test]
229+
fn update_add_github_actions() {
230+
// Add a github actions badge
231+
let (krate, test_badges) = set_up();
232+
233+
let mut badges = HashMap::new();
234+
badges.insert(String::from("github-actions"), test_badges.github_actions_attributes);
235+
krate.update(&badges);
236+
assert_eq!(krate.badges(), vec![test_badges.github_actions]);
237+
}
238+
216239
#[test]
217240
fn update_add_gitlab() {
218241
// Add a gitlab badge
@@ -432,6 +455,40 @@ fn travis_ci_required_keys() {
432455
assert_eq!(krate.badges(), vec![]);
433456
}
434457

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

0 commit comments

Comments
 (0)