Skip to content

Commit

Permalink
Merge pull request #276 from pmiossec/add_notes_for_workitems
Browse files Browse the repository at this point in the history
Add a note on the commit to keep trace of the workitems
  • Loading branch information
sc68cal committed Jan 7, 2013
2 parents 2270c1b + b5fb9b5 commit 5f3c7ae
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
24 changes: 22 additions & 2 deletions GitTfs.VsCommon/TfsHelper.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Net;
using Microsoft.TeamFoundation;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
Expand Down Expand Up @@ -108,11 +109,18 @@ private IGroupSecurityService GroupSecurityService
get { return GetService<IGroupSecurityService>(); }
}

private ILinking _linking;
private ILinking Linking
{
get { return _linking ?? (_linking = GetService<ILinking>()); }
}

public IEnumerable<ITfsChangeset> GetChangesets(string path, long startVersion, GitTfsRemote remote)
{
var changesets = VersionControl.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full,
null, new ChangesetVersionSpec((int) startVersion), VersionSpec.Latest, int.MaxValue, true,
true, true);

return changesets.Cast<Changeset>()
.OrderBy(changeset => changeset.ChangesetId)
.Select(changeset => BuildTfsChangeset(changeset, remote));
Expand All @@ -133,7 +141,19 @@ public virtual int GetRootChangesetForBranch(string tfsPathBranchToCreate, strin
private ITfsChangeset BuildTfsChangeset(Changeset changeset, GitTfsRemote remote)
{
var tfsChangeset = _container.With<ITfsHelper>(this).With<IChangeset>(_bridge.Wrap<WrapperForChangeset, Changeset>(changeset)).GetInstance<TfsChangeset>();
tfsChangeset.Summary = new TfsChangesetInfo {ChangesetId = changeset.ChangesetId, Remote = remote};
tfsChangeset.Summary = new TfsChangesetInfo { ChangesetId = changeset.ChangesetId, Remote = remote };

if (changeset.WorkItems != null)
{
tfsChangeset.Summary.Workitems = changeset.WorkItems.Select(wi => new TfsWorkitem
{
Id = wi.Id,
Title = wi.Title,
Description = wi.Description,
Url = Linking.GetArtifactUrl(wi.Uri.AbsoluteUri)
});
}

return tfsChangeset;
}

Expand Down Expand Up @@ -569,4 +589,4 @@ public IEnumerable<TfsLabel> GetLabels(string tfsPathBranch)
}

}
}
}
6 changes: 6 additions & 0 deletions GitTfs/Core/GitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,11 @@ public void CreateTag(string name, string sha, string comment, string Owner, str
if (_repository.Tags[name] == null)
_repository.ApplyTag(name, sha, new Signature(Owner, emailOwner, new DateTimeOffset(creationDate)), comment);
}

public void CreateNote(string sha, string content, string owner, string emailOwner, DateTime creationDate)
{
Signature author = new Signature(owner, emailOwner, creationDate);
_repository.Notes.Add(new ObjectId(sha), content, author, author, "commits");
}
}
}
12 changes: 11 additions & 1 deletion GitTfs/Core/GitTfsRemote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,17 @@ public void FetchWithMerge(long mergeChangesetId, params string[] parentCommitsH
log.CommitParents.Add(parent);
}
}
UpdateRef(Commit(log), changeset.Summary.ChangesetId);
var commitSha = Commit(log);
UpdateRef(commitSha, changeset.Summary.ChangesetId);
if(changeset.Summary.Workitems.Count() != 0)
{
string workitemNote = "Workitems:\n";
foreach(var workitem in changeset.Summary.Workitems)
{
workitemNote += String.Format("[{0}] {1}\n {2}\n", workitem.Id, workitem.Title, workitem.Url);
}
Repository.CreateNote(commitSha, workitemNote, log.AuthorName, log.AuthorEmail, log.Date);
}
DoGcIfNeeded();
}
}
Expand Down
4 changes: 3 additions & 1 deletion GitTfs/Core/IGitRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using Sep.Git.Tfs.Commands;

Expand Down Expand Up @@ -30,5 +31,6 @@ public interface IGitRepository : IGitHelpers
bool CreateBranch(string gitBranchName, string target);
string FindCommitHashByCommitMessage(string patternToFind);
void CreateTag(string name, string sha, string comment, string Owner, string emailOwner, System.DateTime creationDate);
void CreateNote(string sha, string content, string owner, string emailOwner, DateTime creationDate);
}
}
10 changes: 10 additions & 0 deletions GitTfs/Core/ITfsWorkitem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Sep.Git.Tfs.Core
{
public interface ITfsWorkitem
{
int Id { get; set; }
string Title { get; set; }
string Description { get; set; }
string Url { get; set; }
}
}
4 changes: 3 additions & 1 deletion GitTfs/Core/TfsChangesetInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace Sep.Git.Tfs.Core
using System.Collections.Generic;
namespace Sep.Git.Tfs.Core
{
public class TfsChangesetInfo
{
public IGitTfsRemote Remote { get; set; }
public long ChangesetId { get; set; }
public string GitCommit { get; set; }
public IEnumerable<ITfsWorkitem> Workitems { get; set; }
}
}
10 changes: 10 additions & 0 deletions GitTfs/Core/TfsWorkitem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Sep.Git.Tfs.Core
{
public class TfsWorkitem : ITfsWorkitem
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Url { get; set; }
}
}
4 changes: 3 additions & 1 deletion GitTfs/GitTfs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="..\Version.cs">
<Link>Properties\Version.cs</Link>
</Compile>
<Compile Include="Core\ITfsWorkitem.cs" />
<Compile Include="Commands\Bootstrap.cs" />
<Compile Include="Commands\Checkin.cs" />
<Compile Include="Commands\CheckinTool.cs" />
Expand Down Expand Up @@ -200,6 +201,7 @@
<Compile Include="Core\TfsInterop\NullIdentity.cs" />
<Compile Include="Core\TfsInterop\IChangeset.cs" />
<Compile Include="Core\TfsTreeEntry.cs" />
<Compile Include="Core\TfsWorkitem.cs" />
<Compile Include="Core\TfsWorkspace.cs" />
<Compile Include="Core\TfsWriter.cs" />
<Compile Include="Core\GitTfsException.cs" />
Expand Down Expand Up @@ -291,4 +293,4 @@
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
</Project>
</Project>

0 comments on commit 5f3c7ae

Please sign in to comment.