From b578e2a8c5a1fd55ad6703deaac510a4b4765dd4 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Wed, 4 Dec 2019 21:39:13 +1100 Subject: [PATCH 1/3] add support for Bitbucket Pipelines badges (Shields.io) --- app/components/badge-bitbucket-pipelines.js | 16 +++++++ .../components/badge-bitbucket-pipelines.hbs | 6 +++ src/models/badge.rs | 4 ++ src/tests/badge.rs | 42 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 app/components/badge-bitbucket-pipelines.js create mode 100644 app/templates/components/badge-bitbucket-pipelines.hbs diff --git a/app/components/badge-bitbucket-pipelines.js b/app/components/badge-bitbucket-pipelines.js new file mode 100644 index 0000000000..d3f6037ed6 --- /dev/null +++ b/app/components/badge-bitbucket-pipelines.js @@ -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`; + }), +}); diff --git a/app/templates/components/badge-bitbucket-pipelines.hbs b/app/templates/components/badge-bitbucket-pipelines.hbs new file mode 100644 index 0000000000..b5b6b29efe --- /dev/null +++ b/app/templates/components/badge-bitbucket-pipelines.hbs @@ -0,0 +1,6 @@ + + {{ text }} + diff --git a/src/models/badge.rs b/src/models/badge.rs index 7c91cad792..c6c986b8e7 100644 --- a/src/models/badge.rs +++ b/src/models/badge.rs @@ -68,6 +68,10 @@ pub enum Badge { branch: Option, service: Option, }, + BitbucketPipelines { + repository: String, + branch: String, + }, Maintenance { status: MaintenanceStatus, }, diff --git a/src/tests/badge.rs b/src/tests/badge.rs index 7814d51b5b..dec663c266 100644 --- a/src/tests/badge.rs +++ b/src/tests/badge.rs @@ -23,6 +23,8 @@ struct BadgeRef { circle_ci_attributes: HashMap, cirrus_ci: Badge, cirrus_ci_attributes: HashMap, + bitbucket_pipelines: Badge, + bitbucket_pipelines_attributes: HashMap, maintenance: Badge, maintenance_attributes: HashMap, } @@ -144,6 +146,14 @@ 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, }; @@ -175,6 +185,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, }; @@ -313,6 +325,17 @@ 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 @@ -587,6 +610,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 From 19f42a46a7d09375d677cdfb8d0e932fc74d2e16 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Wed, 4 Dec 2019 22:45:23 +1100 Subject: [PATCH 2/3] fix dirty cargo fmt --- src/tests/badge.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tests/badge.rs b/src/tests/badge.rs index dec663c266..db3ccce24d 100644 --- a/src/tests/badge.rs +++ b/src/tests/badge.rs @@ -151,7 +151,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) { 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("repository"), String::from("rust-lang/rust")); badge_attributes_bitbucket_pipelines.insert(String::from("branch"), String::from("beta")); let maintenance = Badge::Maintenance { @@ -331,7 +332,10 @@ fn update_add_bitbucket_pipelines() { let (krate, test_badges) = set_up(); let mut badges = HashMap::new(); - badges.insert(String::from("bitbucket-pipelines"), test_badges.bitbucket_pipelines_attributes); + badges.insert( + String::from("bitbucket-pipelines"), + test_badges.bitbucket_pipelines_attributes, + ); krate.update(&badges); assert_eq!(krate.badges(), vec![test_badges.bitbucket_pipelines]); } From 79f15b479fb03c48c3b07b393874cccd35689b07 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Thu, 5 Dec 2019 11:33:06 +1100 Subject: [PATCH 3/3] fix where {{ repository }} should have been used --- app/templates/components/badge-bitbucket-pipelines.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/components/badge-bitbucket-pipelines.hbs b/app/templates/components/badge-bitbucket-pipelines.hbs index b5b6b29efe..5c1abebe40 100644 --- a/app/templates/components/badge-bitbucket-pipelines.hbs +++ b/app/templates/components/badge-bitbucket-pipelines.hbs @@ -1,4 +1,4 @@ - +