Skip to content

Commit

Permalink
Auto merge of #1934 - delan:delan/Bitbucket-Pipelines-badges, r=carol…
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Dec 5, 2019
2 parents ca965ce + 79f15b4 commit 05b1399
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/components/badge-bitbucket-pipelines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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'));
}),
text: computed('badge.attributes.branch', function() {
const branch = this.get('badge.attributes.branch');
return `Bitbucket Pipelines build status for the ${branch} branch`;
}),
});
6 changes: 6 additions & 0 deletions app/templates/components/badge-bitbucket-pipelines.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a href="https://bitbucket.org/{{ repository }}/addon/pipelines/home#!/results/branch/{{ branch }}/page/1">
<img
src="https://img.shields.io/bitbucket/pipelines/{{ repository }}/{{ 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 @@ -68,6 +68,10 @@ pub enum Badge {
branch: Option<String>,
service: Option<String>,
},
BitbucketPipelines {
repository: String,
branch: String,
},
Maintenance {
status: MaintenanceStatus,
},
Expand Down
46 changes: 46 additions & 0 deletions src/tests/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct BadgeRef {
circle_ci_attributes: HashMap<String, String>,
cirrus_ci: Badge,
cirrus_ci_attributes: HashMap<String, String>,
bitbucket_pipelines: Badge,
bitbucket_pipelines_attributes: HashMap<String, String>,
maintenance: Badge,
maintenance_attributes: HashMap<String, String>,
}
Expand Down Expand Up @@ -144,6 +146,15 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
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 bitbucket_pipelines = Badge::BitbucketPipelines {
repository: String::from("rust-lang/rust"),
branch: String::from("beta"),
};
let mut badge_attributes_bitbucket_pipelines = HashMap::new();
badge_attributes_bitbucket_pipelines
.insert(String::from("repository"), String::from("rust-lang/rust"));
badge_attributes_bitbucket_pipelines.insert(String::from("branch"), String::from("beta"));

let maintenance = Badge::Maintenance {
status: MaintenanceStatus::LookingForMaintainer,
};
Expand Down Expand Up @@ -175,6 +186,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
circle_ci_attributes: badge_attributes_circle_ci,
cirrus_ci,
cirrus_ci_attributes: badge_attributes_cirrus_ci,
bitbucket_pipelines,
bitbucket_pipelines_attributes: badge_attributes_bitbucket_pipelines,
maintenance,
maintenance_attributes,
};
Expand Down Expand Up @@ -313,6 +326,20 @@ fn update_add_cirrus_ci() {
assert_eq!(krate.badges(), vec![test_badges.cirrus_ci]);
}

#[test]
fn update_add_bitbucket_pipelines() {
// Add a Bitbucket Pipelines badge
let (krate, test_badges) = set_up();

let mut badges = HashMap::new();
badges.insert(
String::from("bitbucket-pipelines"),
test_badges.bitbucket_pipelines_attributes,
);
krate.update(&badges);
assert_eq!(krate.badges(), vec![test_badges.bitbucket_pipelines]);
}

#[test]
fn update_add_maintenance() {
// Add a maintenance badge
Expand Down Expand Up @@ -587,6 +614,25 @@ fn cirrus_ci_required_keys() {
assert_eq!(krate.badges(), vec![]);
}

#[test]
fn bitbucket_pipelines_required_keys() {
// Add a Bitbucket Pipelines badge missing a required field
let (krate, test_badges) = set_up();

for required in &["repository", "branch"] {
let mut attributes = test_badges.bitbucket_pipelines_attributes.clone();
attributes.remove(*required);

let mut badges = HashMap::new();
badges.insert(String::from("bitbucket-pipelines"), attributes);

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

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

0 comments on commit 05b1399

Please sign in to comment.