Skip to content

Support CircleCI badges #807

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

Merged
merged 2 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/components/badge-circle-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ember from 'ember';

export default Ember.Component.extend({
tagName: 'span',
classNames: ['badge'],
repository: Ember.computed.alias('badge.attributes.repository'),
branch: Ember.computed('badge.attributes.branch', function() {
return encodeURIComponent(this.get('badge.attributes.branch') || 'master');
}),
text: Ember.computed('branch', function() {
return `Circle CI build status for the ${ this.get('branch') } branch`;
})
});
6 changes: 6 additions & 0 deletions app/templates/components/badge-circle-ci.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="https://circleci.com/gh/{{ repository }}">
<img
src="https://circleci.com/gh/{{ repository }}/tree/{{ branch }}.svg?style=shield"
alt="{{ text }}"
title="{{ text }}" />
</a>
4 changes: 4 additions & 0 deletions src/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub enum Badge {
repository: String,
branch: Option<String>,
},
CircleCi {
repository: String,
branch: Option<String>,
},
IsItMaintainedIssueResolution { repository: String },
IsItMaintainedOpenIssues { repository: String },
Codecov {
Expand Down
42 changes: 42 additions & 0 deletions src/tests/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct BadgeRef {
codecov_attributes: HashMap<String, String>,
coveralls: Badge,
coveralls_attributes: HashMap<String, String>,
circle_ci: Badge,
circle_ci_attributes: HashMap<String, String>,
}

fn set_up() -> (Arc<App>, Crate, BadgeRef) {
Expand Down Expand Up @@ -96,6 +98,14 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
badge_attributes_coveralls.insert(String::from("repository"), String::from("rust-lang/rust"));
badge_attributes_coveralls.insert(String::from("service"), String::from("github"));

let circle_ci = Badge::CircleCi {
repository: String::from("rust-lang/rust"),
branch: Some(String::from("beta")),
};
let mut badge_attributes_circle_ci = HashMap::new();
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 badges = BadgeRef {
appveyor: appveyor,
appveyor_attributes: badge_attributes_appveyor,
Expand All @@ -112,6 +122,8 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
codecov_attributes: badge_attributes_codecov,
coveralls: coveralls,
coveralls_attributes: badge_attributes_coveralls,
circle_ci: circle_ci,
circle_ci_attributes: badge_attributes_circle_ci,
};
(app, krate, badges)
}
Expand Down Expand Up @@ -223,6 +235,18 @@ fn update_add_coveralls() {
assert_eq!(krate.badges(&conn).unwrap(), vec![test_badges.coveralls]);
}

#[test]
fn update_add_circle_ci() {
// Add a CircleCI badge
let (app, krate, test_badges) = set_up();
let conn = app.diesel_database.get().unwrap();

let mut badges = HashMap::new();
badges.insert(String::from("circle-ci"), test_badges.circle_ci_attributes);
Badge::update_crate(&conn, &krate, Some(&badges)).unwrap();
assert_eq!(krate.badges(&conn).unwrap(), vec![test_badges.circle_ci]);
}

#[test]
fn replace_badge() {
// Replacing one badge with another
Expand Down Expand Up @@ -438,6 +462,24 @@ fn coveralls_required_keys() {
assert_eq!(krate.badges(&conn).unwrap(), vec![]);
}

#[test]
fn circle_ci_required_keys() {
// Add a CircleCI badge missing a required field
let (app, krate, mut test_badges) = set_up();
let conn = app.diesel_database.get().unwrap();

let mut badges = HashMap::new();

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

let invalid_badges = Badge::update_crate(&conn, &krate, Some(&badges)).unwrap();
assert_eq!(invalid_badges.len(), 1);
assert!(invalid_badges.contains(&"circle-ci"));
assert_eq!(krate.badges(&conn).unwrap(), vec![]);
}

#[test]
fn unknown_badge() {
// Add an unknown badge
Expand Down