Skip to content
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

add support for Bitbucket Pipelines badges (Shields.io) #1934

Merged
merged 3 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
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'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the URL encoding is mandatory (e.g. this link doesn’t work)

}),
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/delan/nonymous/addon/pipelines/home#!/results/branch/{{ branch }}/page/1">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the /page/1 is mandatory (e.g. this link doesn’t work)

Copy link
Member

@carols10cents carols10cents Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL looks like it has your username and project in it? It should use {{ repository }}, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 79f15b4

<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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve made the branch attribute required for now, because while Shields.io allows the branch to be omitted, it assumes the default branch is “master”, but Bitbucket lets you choose any branch as the default branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(strictly speaking, this is a bug that Shields.io could fix by querying the Bitbucket API for the repository’s main branch, but that’s a job for another day)

},
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