Skip to content

Instantly share code, notes, and snippets.

@jaydanielian
Created February 13, 2014 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaydanielian/8977973 to your computer and use it in GitHub Desktop.
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.
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