Skip to content

Commit

Permalink
Auto merge of #1782 - jonhoo:cirrus-ci-badge, r=sgrif
Browse files Browse the repository at this point in the history
Support Cirrus CI badges

Upstream API: https://cirrus-ci.org/guide/writing-tasks/#embedded-badges

Modeled after #807.
  • Loading branch information
bors committed Jul 16, 2019
2 parents 2a036e5 + a7c8fc7 commit f3127bb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/components/badge-cirrus-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import Component from '@ember/component';

export default Component.extend({
tagName: 'span',
classNames: ['badge'],
repository: alias('badge.attributes.repository'),
branch: computed('badge.attributes.branch', function() {
return encodeURIComponent(this.get('badge.attributes.branch') || 'master');
}),
text: computed('branch', function() {
return `Cirrus CI build status for the ${this.branch} branch`;
}),
});
6 changes: 6 additions & 0 deletions app/templates/components/badge-cirrus-ci.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="https://cirrus-ci.com/github/{{ repository }}">
<img
src="https://api.cirrus-ci.com/github/{{ repository }}.svg?branch={{ branch }}"
alt="{{ text }}"
title="{{ text }}">
</a>
4 changes: 4 additions & 0 deletions src/models/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub enum Badge {
repository: String,
branch: Option<String>,
},
CirrusCi {
repository: String,
branch: Option<String>,
},
IsItMaintainedIssueResolution {
repository: String,
},
Expand Down
40 changes: 40 additions & 0 deletions src/tests/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct BadgeRef {
coveralls_attributes: HashMap<String, String>,
circle_ci: Badge,
circle_ci_attributes: HashMap<String, String>,
cirrus_ci: Badge,
cirrus_ci_attributes: HashMap<String, String>,
maintenance: Badge,
maintenance_attributes: HashMap<String, String>,
}
Expand Down Expand Up @@ -134,6 +136,14 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
badge_attributes_circle_ci.insert(String::from("branch"), String::from("beta"));
badge_attributes_circle_ci.insert(String::from("repository"), String::from("rust-lang/rust"));

let cirrus_ci = Badge::CirrusCi {
repository: String::from("rust-lang/rust"),
branch: Some(String::from("beta")),
};
let mut badge_attributes_cirrus_ci = HashMap::new();
badge_attributes_cirrus_ci.insert(String::from("branch"), String::from("beta"));
badge_attributes_cirrus_ci.insert(String::from("repository"), String::from("rust-lang/rust"));

let maintenance = Badge::Maintenance {
status: MaintenanceStatus::LookingForMaintainer,
};
Expand Down Expand Up @@ -163,6 +173,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
coveralls_attributes: badge_attributes_coveralls,
circle_ci,
circle_ci_attributes: badge_attributes_circle_ci,
cirrus_ci,
cirrus_ci_attributes: badge_attributes_cirrus_ci,
maintenance,
maintenance_attributes,
};
Expand Down Expand Up @@ -290,6 +302,17 @@ fn update_add_circle_ci() {
assert_eq!(krate.badges(), vec![test_badges.circle_ci]);
}

#[test]
fn update_add_cirrus_ci() {
// Add a Cirrus CI badge
let (krate, test_badges) = set_up();

let mut badges = HashMap::new();
badges.insert(String::from("cirrus-ci"), test_badges.cirrus_ci_attributes);
krate.update(&badges);
assert_eq!(krate.badges(), vec![test_badges.cirrus_ci]);
}

#[test]
fn update_add_maintenance() {
// Add a maintenance badge
Expand Down Expand Up @@ -547,6 +570,23 @@ fn circle_ci_required_keys() {
assert_eq!(krate.badges(), vec![]);
}

#[test]
fn cirrus_ci_required_keys() {
// Add a Cirrus CI badge missing a required field
let (krate, mut test_badges) = set_up();

let mut badges = HashMap::new();

// Repository is a required key
test_badges.cirrus_ci_attributes.remove("repository");
badges.insert(String::from("cirrus-ci"), test_badges.cirrus_ci_attributes);

let invalid_badges = krate.update(&badges);
assert_eq!(invalid_badges.len(), 1);
assert_eq!(invalid_badges.first().unwrap(), "cirrus-ci");
assert_eq!(krate.badges(), vec![]);
}

#[test]
fn maintenance_required_keys() {
// Add a maintenance badge missing a required field
Expand Down

0 comments on commit f3127bb

Please sign in to comment.