Created
February 13, 2014 16:08
-
-
Save jaydanielian/8977973 to your computer and use it in GitHub Desktop.
PT API integration. Once we have the list of stories (from parsing git), we query the PT API to get the stories, then if they are in the finished state, we mark them as delivered, and apply our current build tag as a PT label to each story.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using PivotalTrackerDotNet; | |
using PivotalTrackerDotNet.Domain; | |
namespace Dublabs.CircleBack.PivotalTrackGit | |
{ | |
class PTService | |
{ | |
int _projectId = 0; | |
PivotalTrackerDotNet.Domain.AuthenticationToken _authToken = null; | |
public PTService(string username, string pwd, int projectId) | |
{ | |
PivotalTrackerDotNet.Domain.AuthenticationToken authToken = AuthenticationService.Authenticate(username, pwd); | |
_projectId = projectId; | |
_authToken = authToken; | |
} | |
public void UpdateAndDeliverStoriesWithLabels(List<string> storyIds, string currentTag) | |
{ | |
string labelToApply = string.Format("3.0 (build {0})", currentTag).ToLower(); | |
var storyService = new StoryService(_authToken); | |
StringBuilder sb = new StringBuilder(); | |
if (storyIds != null && storyIds.Any()) | |
{ | |
foreach (var s in storyIds) | |
{ | |
if (!string.IsNullOrEmpty(sb.ToString())) | |
{ | |
sb.Append(","); | |
} | |
sb.Append(s); | |
} | |
string filterIdString = sb.ToString(); | |
string filter = "id:" + filterIdString; | |
List<Story> stories = storyService.GetAllStoriesMatchingFilter(_projectId, filter); | |
//now that we have the stories we need to apply the label and update | |
foreach (var s in stories) | |
{ | |
string newLabel = string.Empty; | |
string currentLabels = s.Labels; | |
if (string.IsNullOrEmpty(currentLabels)) | |
{ | |
newLabel = labelToApply; | |
} | |
else | |
{ | |
newLabel = currentLabels + "," + labelToApply; | |
} | |
if ((currentLabels != null && !currentLabels.Contains(labelToApply)) || string.IsNullOrEmpty(currentLabels)) | |
{ | |
s.Labels = newLabel; | |
} | |
if (s.CurrentState == StoryStatus.Finished) | |
{ | |
s.CurrentState = StoryStatus.Delivered; | |
storyService.UpdateStory(_projectId, s); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment