Skip to content

Commit

Permalink
Merge pull request #12 from AntonovAv/dev/teamcity-resource
Browse files Browse the repository at this point in the history
Teamcity Resource - fix teamcity fake api
close #3
  • Loading branch information
AntonovAv committed Mar 5, 2017
2 parents b35a62e + 3cf4530 commit 3d534ba
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 115 deletions.
2 changes: 1 addition & 1 deletion client/containers/Home/duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function loadBuilds() {
return {
types: [LOAD_BUILDS, LOAD_BUILDS_SUCCESS, LOAD_BUILDS_FAILURE],
promise: (client) => {
return client.get('api/builds')
return client.get('api/buildTypes')
}
}
}
1 change: 0 additions & 1 deletion client/containers/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Home extends PureComponent {
}

Home.propTypes = {
children: PropTypes.node.isRequired,
isLoading: PropTypes.bool,
buildsList: PropTypes.arrayOf(PropTypes.string),
buildServer: PropTypes.string,
Expand Down
2 changes: 1 addition & 1 deletion fakeTeamcity/routes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/guestAuth/app/rest/": "/",
"/buildTypes": "/buildTypes",
"/buildTypes/id::buildTypeId/builds": "/builds?id=:buildTypeId"
"/buildTypes/id::buildTypeId/builds": "/:buildTypeId"
}
216 changes: 107 additions & 109 deletions fakeTeamcity/teamcity.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,113 +42,111 @@
}
]
},
"builds": [
{
"id": "NetCommunityProjects_Femah_Commit",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Commit/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Commit/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 145897,
"buildTypeId": "NetCommunityProjects_Femah_Commit",
"number": "0.1.78.209",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:145897"
},
{
"id": 137748,
"buildTypeId": "NetCommunityProjects_Femah_Commit",
"number": "0.1.77.194",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:137748"
}
]
},
{
"id": "NetCommunityProjects_Femah_Publish",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Publish/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Publish/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 129546,
"buildTypeId": "NetCommunityProjects_Femah_Publish",
"number": "0.1.70-beta",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:129546",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=129546&buildTypeId=NetCommunityProjects_Femah_Publish"
},
{
"id": 129545,
"buildTypeId": "NetCommunityProjects_Femah_Publish",
"number": "16",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:129545",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=129545&buildTypeId=NetCommunityProjects_Femah_Publish"
}
]
},
{
"id": "NetProductsExtensions_Trunk_HeapViewer",
"count": 0,
"href": "/guestAuth/app/rest/buildTypes/id:NetProductsExtensions_Trunk_HeapViewer/builds?locator=running:any,count:2"
},
{
"id": "Checkstyle_ContributionIdeaInspectionsMaster",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:Checkstyle_ContributionIdeaInspectionsMaster/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:Checkstyle_ContributionIdeaInspectionsMaster/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 994276,
"buildTypeId": "Checkstyle_ContributionIdeaInspectionsMaster",
"number": "69",
"status": "SUCCESS",
"state": "running",
"href": "/guestAuth/app/rest/builds/id:994276",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994276&buildTypeId=Checkstyle_ContributionIdeaInspectionsMaster"
},
{
"id": 994117,
"buildTypeId": "Checkstyle_ContributionIdeaInspectionsMaster",
"number": "68",
"status": "FAILURE",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:994117",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994117&buildTypeId=Checkstyle_ContributionIdeaInspectionsMaster"
}
]
},
{
"id": "Epigenome_Cmeth",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:Epigenome_Cmeth/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:Epigenome_Cmeth/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 994276,
"buildTypeId": "Epigenome_Cmeth",
"number": "69",
"status": "SUCCESS",
"state": "running",
"href": "/guestAuth/app/rest/builds/id:994276",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994276&buildTypeId=Epigenome_Cmeth"
},
{
"id": 994117,
"buildTypeId": "Epigenome_Cmeth",
"number": "68",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:994117",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994117&buildTypeId=Epigenome_Cmeth"
}
]
}
]
"NetCommunityProjects_Femah_Publish": {
"id": "NetCommunityProjects_Femah_Publish",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Publish/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Publish/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 129546,
"buildTypeId": "NetCommunityProjects_Femah_Publish",
"number": "0.1.70-beta",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:129546",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=129546&buildTypeId=NetCommunityProjects_Femah_Publish"
},
{
"id": 129545,
"buildTypeId": "NetCommunityProjects_Femah_Publish",
"number": "16",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:129545",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=129545&buildTypeId=NetCommunityProjects_Femah_Publish"
}
]
},
"NetCommunityProjects_Femah_Commit": {
"id": "NetCommunityProjects_Femah_Commit",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Commit/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:NetCommunityProjects_Femah_Commit/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 145897,
"buildTypeId": "NetCommunityProjects_Femah_Commit",
"number": "0.1.78.209",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:145897"
},
{
"id": 137748,
"buildTypeId": "NetCommunityProjects_Femah_Commit",
"number": "0.1.77.194",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:137748"
}
]
},
"NetProductsExtensions_Trunk_HeapViewer": {
"id": "NetProductsExtensions_Trunk_HeapViewer",
"count": 0,
"href": "/guestAuth/app/rest/buildTypes/id:NetProductsExtensions_Trunk_HeapViewer/builds?locator=running:any,count:2"
},
"Checkstyle_ContributionIdeaInspectionsMaster": {
"id": "Checkstyle_ContributionIdeaInspectionsMaster",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:Checkstyle_ContributionIdeaInspectionsMaster/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:Checkstyle_ContributionIdeaInspectionsMaster/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 994276,
"buildTypeId": "Checkstyle_ContributionIdeaInspectionsMaster",
"number": "69",
"status": "SUCCESS",
"state": "running",
"href": "/guestAuth/app/rest/builds/id:994276",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994276&buildTypeId=Checkstyle_ContributionIdeaInspectionsMaster"
},
{
"id": 994117,
"buildTypeId": "Checkstyle_ContributionIdeaInspectionsMaster",
"number": "68",
"status": "FAILURE",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:994117",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994117&buildTypeId=Checkstyle_ContributionIdeaInspectionsMaster"
}
]
},
"Epigenome_Cmeth": {
"id": "Epigenome_Cmeth",
"count": 2,
"href": "/guestAuth/app/rest/buildTypes/id:Epigenome_Cmeth/builds?locator=running:any,count:2",
"nextHref": "/guestAuth/app/rest/buildTypes/id:Epigenome_Cmeth/builds?locator=running:any,count:2,start:2",
"build": [
{
"id": 994276,
"buildTypeId": "Epigenome_Cmeth",
"number": "69",
"status": "SUCCESS",
"state": "running",
"href": "/guestAuth/app/rest/builds/id:994276",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994276&buildTypeId=Epigenome_Cmeth"
},
{
"id": 994117,
"buildTypeId": "Epigenome_Cmeth",
"number": "68",
"status": "SUCCESS",
"state": "finished",
"href": "/guestAuth/app/rest/builds/id:994117",
"webUrl": "https://teamcity.jetbrains.com/viewLog.html?buildId=994117&buildTypeId=Epigenome_Cmeth"
}
]
}
}
13 changes: 10 additions & 3 deletions server/api/clientApi.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
module.exports = (app) => {
const temcityResource = require('../teamcity/resource')
const R = require('ramda')

module.exports = (app) => {
app.all('/api/', function(request, response, next) {
response.contentType('json')
next()
})

app.get('/api/builds', function(request, response) {
response.send(['ODIN', 'DVA', 'THREE_BUILD_ID'])
app.get('/api/buildTypes', function(request, response) {
temcityResource.getBuildTypes('http://localhost:3001')
.then((data) => {
const ids = R.map(({id}) => id, data)
response.send(ids)
})
.catch(console.error)
})

return app
Expand Down
69 changes: 69 additions & 0 deletions server/teamcity/resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const axios = require('axios')
const R = require('ramda')

const BUILD_TYPES_URL = '/guestAuth/app/rest/buildTypes'

/**
* Retrieve build type ids grouped by project ids
*
* @param host teamcity host
*/
module.exports.getBuildTypes = (host) => {
return new Promise((resolve, reject) => {
axios
.get(host + BUILD_TYPES_URL, {
headers: {
'Accept': 'application/json'
}
})
.then(({data}) => {
const result = R.map((buildType) => {
const {id, projectId} = buildType
return {
id,
projectId,
}
}, data.buildType)
resolve(result)
})
.catch((error) => {
reject(error)
})
})
}

/**
* Retrieve buildType builds statuses
*
* @param host teamcity host
* @param buildTypeId target id of build type
* @param count needed number of builds
*/
module.exports.getBuildStatus = (host, buildTypeId, count = 2) => {
return new Promise((resolve, reject) => {
axios
.get(host + BUILD_TYPES_URL + `/id:${buildTypeId}/builds?locator=count:${count},running:any`, {
headers: {
'Accept': 'application/json'
}
})
.then(({data}) => {
const {count, build} = data
if (count === 0) {
resolve([])
} else {
resolve(R.map((build) => {
const {buildTypeId, status, state} = build
return {
id: buildTypeId,
state,
status
}
}, build))
}
})
.catch((error) => {
reject(error)
})
})
}

0 comments on commit 3d534ba

Please sign in to comment.