Skip to content

Commit

Permalink
Auto merge of #1551 - robertohuertasm:azure-devops-badge, r=carols10c…
Browse files Browse the repository at this point in the history
…ents

Add support for Azure DevOps badge

I added a project of mine that is already using `Azure Devops` into `fixtures/crates.js`. Let me know if that's an inconvenience and I'll remove it. I just put it there to easily see that everything was working as expected.

I also added some tests by following the existing code example.

See also rust-lang/cargo#6264
  • Loading branch information
bors committed Feb 12, 2019
2 parents ebab2b0 + 5eba143 commit 6fff863
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/components/badge-azure-devops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';

export default Component.extend({
tagName: 'span',
classNames: ['badge'],
project: alias('badge.attributes.project'),
pipeline: alias('badge.attributes.pipeline'),
build: computed('badge.attributes.build', function() {
return this.get('badge.attributes.build') || '1';
}),
text: computed('pipeline', function() {
return `Azure Devops build status for the ${this.pipeline} pipeline`;
}),
});
3 changes: 3 additions & 0 deletions app/templates/components/badge-azure-devops.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="https://dev.azure.com/{{ project }}/_build/latest?definitionId={{ build }}">
<img src="https://dev.azure.com/{{ project }}/_apis/build/status/{{ pipeline }}" alt="{{ text }}" title="{{ text }}">
</a>
8 changes: 8 additions & 0 deletions mirage/fixtures/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ export default [
repository: 'https://github.com/huonw/external_mixin',
updated_at: '2015-02-27T11:52:13Z',
badges: [
{
attributes: {
project: 'robertohuertasm/github-oss',
pipeline: 'microserver',
build: '2',
},
badge_type: 'azure-devops',
},
{
attributes: {
repository: 'huonw/external_mixin',
Expand Down
5 changes: 5 additions & 0 deletions src/models/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub enum Badge {
project_name: Option<String>,
service: Option<String>,
},
AzureDevops {
project: String,
pipeline: String,
build: Option<String>,
},
#[serde(rename = "gitlab")]
GitLab {
repository: String,
Expand Down
48 changes: 48 additions & 0 deletions src/tests/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct BadgeRef {
travis_ci_attributes: HashMap<String, String>,
gitlab: Badge,
gitlab_attributes: HashMap<String, String>,
azure_devops: Badge,
azure_devops_attributes: HashMap<String, String>,
isitmaintained_issue_resolution: Badge,
isitmaintained_issue_resolution_attributes: HashMap<String, String>,
isitmaintained_open_issues: Badge,
Expand Down Expand Up @@ -80,6 +82,16 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
badge_attributes_gitlab.insert(String::from("branch"), String::from("beta"));
badge_attributes_gitlab.insert(String::from("repository"), String::from("rust-lang/rust"));

let azure_devops = Badge::AzureDevops {
project: String::from("rust-lang"),
pipeline: String::from("rust"),
build: Some(String::from("2")),
};
let mut badge_attributes_azure_devops = HashMap::new();
badge_attributes_azure_devops.insert(String::from("project"), String::from("rust-lang"));
badge_attributes_azure_devops.insert(String::from("pipeline"), String::from("rust"));
badge_attributes_azure_devops.insert(String::from("build"), String::from("2"));

let isitmaintained_issue_resolution = Badge::IsItMaintainedIssueResolution {
repository: String::from("rust-lang/rust"),
};
Expand Down Expand Up @@ -138,6 +150,8 @@ fn set_up() -> (BadgeTestCrate, BadgeRef) {
travis_ci_attributes: badge_attributes_travis_ci,
gitlab,
gitlab_attributes: badge_attributes_gitlab,
azure_devops,
azure_devops_attributes: badge_attributes_azure_devops,
isitmaintained_issue_resolution,
isitmaintained_issue_resolution_attributes:
badge_attributes_isitmaintained_issue_resolution,
Expand Down Expand Up @@ -198,6 +212,20 @@ fn update_add_gitlab() {
assert_eq!(krate.badges(), vec![test_badges.gitlab]);
}

#[test]
fn update_add_azure_devops() {
// Add a azure devops badge
let (krate, test_badges) = set_up();

let mut badges = HashMap::new();
badges.insert(
String::from("azure-devops"),
test_badges.azure_devops_attributes,
);
krate.update(&badges);
assert_eq!(krate.badges(), vec![test_badges.azure_devops]);
}

#[test]
fn update_add_isitmaintained_issue_resolution() {
// Add a isitmaintained_issue_resolution badge
Expand Down Expand Up @@ -398,6 +426,26 @@ fn gitlab_required_keys() {
assert_eq!(krate.badges(), vec![]);
}

#[test]
fn azure_devops_required_keys() {
// Add a azure devops badge missing a required field
let (krate, mut test_badges) = set_up();

let mut badges = HashMap::new();

// project is a required key
test_badges.azure_devops_attributes.remove("project");
badges.insert(
String::from("azure-devops"),
test_badges.azure_devops_attributes,
);

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

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

0 comments on commit 6fff863

Please sign in to comment.