-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
645 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Gallifrey.Jira.Enum; | ||
using Gallifrey.Jira.Model; | ||
|
||
namespace Gallifrey.Jira | ||
{ | ||
public interface IJiraClient | ||
{ | ||
User GetCurrentUser(); | ||
Issue GetIssue(string issueRef); | ||
Issue GetIssueWithWorklogs(string issueRef); | ||
IEnumerable<Issue> GetIssuesFromFilter(string filterName); | ||
IEnumerable<Issue> GetIssuesFromJql(string jql); | ||
IEnumerable<Project> GetProjects(); | ||
IEnumerable<Filter> GetFilters(); | ||
Transitions GetIssueTransitions(string issueRef); | ||
void TransitionIssue(string issueRef, string transitionName); | ||
void AddWorkLog(string issueRef, WorkLogStrategy workLogStrategy, string comment, TimeSpan timeSpent, DateTime logDate, TimeSpan? remainingTime = null); | ||
void AssignIssue(string issueRef, string userName); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Atlassian.Jira; | ||
using Gallifrey.Jira.Enum; | ||
using Gallifrey.Jira.Model; | ||
using Issue = Gallifrey.Jira.Model.Issue; | ||
using Project = Gallifrey.Jira.Model.Project; | ||
|
||
namespace Gallifrey.Jira | ||
{ | ||
public class JiraSoapClient : IJiraClient | ||
{ | ||
private readonly string username; | ||
private readonly Atlassian.Jira.Jira client; | ||
|
||
public JiraSoapClient(string baseUrl, string username, string password) | ||
{ | ||
this.username = username; | ||
client = new Atlassian.Jira.Jira(baseUrl, username, password) { MaxIssuesPerRequest = 999 }; | ||
} | ||
|
||
public User GetCurrentUser() | ||
{ | ||
client.GetAccessToken(); | ||
return new User | ||
{ | ||
name = username, | ||
active = true | ||
}; | ||
} | ||
|
||
public Issue GetIssue(string issueRef) | ||
{ | ||
var issue = client.GetIssue(issueRef); | ||
return new Issue | ||
{ | ||
key = issue.Key.Value, | ||
fields = new Fields | ||
{ | ||
project = new Project | ||
{ | ||
key = issue.Project | ||
}, | ||
status = new Status | ||
{ | ||
name = issue.Status.Name, | ||
id = issue.Status.Id | ||
}, | ||
summary = issue.Summary | ||
} | ||
}; | ||
} | ||
|
||
public Issue GetIssueWithWorklogs(string issueRef) | ||
{ | ||
var issue = client.GetIssue(issueRef); | ||
var worklogs = issue.GetWorklogs().Select(worklog => new WorkLog { author = new User { name = worklog.Author }, comment = worklog.Comment, started = worklog.StartDate.Value, timeSpent = worklog.TimeSpent, timeSpentSeconds = worklog.TimeSpentInSeconds }).ToList(); | ||
return new Issue | ||
{ | ||
key = issue.Key.Value, | ||
fields = new Fields | ||
{ | ||
project = new Project | ||
{ | ||
key = issue.Project | ||
}, | ||
status = new Status | ||
{ | ||
name = issue.Status.Name, | ||
id = issue.Status.Id | ||
}, | ||
worklog = new WorkLogs | ||
{ | ||
maxResults = worklogs.Count(), | ||
total = worklogs.Count(), | ||
worklogs = worklogs | ||
}, | ||
summary = issue.Summary, | ||
} | ||
}; | ||
} | ||
|
||
public IEnumerable<Issue> GetIssuesFromFilter(string filterName) | ||
{ | ||
var issues = client.GetIssuesFromFilter(filterName, 0, 999); | ||
return issues.Select(issue => new Issue | ||
{ | ||
key = issue.Key.Value, | ||
fields = new Fields | ||
{ | ||
project = new Project | ||
{ | ||
key = issue.Project | ||
}, | ||
status = new Status | ||
{ | ||
name = issue.Status.Name, | ||
id = issue.Status.Id | ||
}, | ||
summary = issue.Summary | ||
} | ||
}); | ||
} | ||
|
||
public IEnumerable<Issue> GetIssuesFromJql(string jql) | ||
{ | ||
var issues = client.GetIssuesFromJql(jql, 999); | ||
return issues.Select(issue => new Issue | ||
{ | ||
key = issue.Key.Value, | ||
fields = new Fields | ||
{ | ||
project = new Project | ||
{ | ||
key = issue.Project | ||
}, | ||
status = new Status | ||
{ | ||
name = issue.Status.Name, | ||
id = issue.Status.Id | ||
}, | ||
summary = issue.Summary | ||
} | ||
}); | ||
} | ||
|
||
public IEnumerable<Project> GetProjects() | ||
{ | ||
var projects = client.GetProjects(); | ||
return projects.Select(project => new Project { key = project.Key, name = project.Name }); | ||
} | ||
|
||
public IEnumerable<Filter> GetFilters() | ||
{ | ||
var returnedFilters = client.GetFilters(); | ||
return returnedFilters.Select(filter => new Filter { name = filter.Name }); | ||
} | ||
|
||
public Transitions GetIssueTransitions(string issueRef) | ||
{ | ||
var issue = client.GetIssue(issueRef); | ||
var statuses = issue.GetAvailableActions().Select(action => new Status { name = action.Name, id = action.Id }); | ||
return new Transitions { transitions = statuses.ToList() }; | ||
} | ||
|
||
public void TransitionIssue(string issueRef, string transitionName) | ||
{ | ||
var issue = client.GetIssue(issueRef); | ||
issue.WorkflowTransition(transitionName); | ||
} | ||
|
||
public void AddWorkLog(string issueRef, WorkLogStrategy workLogStrategy, string comment, TimeSpan timeSpent, DateTime logDate, TimeSpan? remainingTime = null) | ||
{ | ||
if (logDate.Kind != DateTimeKind.Local) logDate = DateTime.SpecifyKind(logDate, DateTimeKind.Local); | ||
|
||
var issue = client.GetIssue(issueRef); | ||
|
||
var worklog = new Worklog(string.Format("{0}h {1}m", timeSpent.Hours, timeSpent.Minutes), logDate, comment); | ||
string remaining = null; | ||
if (remainingTime.HasValue) | ||
{ | ||
remaining = string.Format("{0}h {1}m", remainingTime.Value.Hours, remainingTime.Value.Minutes); | ||
} | ||
|
||
WorklogStrategy strategy; | ||
switch (workLogStrategy) | ||
{ | ||
case WorkLogStrategy.Automatic: | ||
strategy = WorklogStrategy.AutoAdjustRemainingEstimate; | ||
break; | ||
case WorkLogStrategy.LeaveRemaining: | ||
strategy = WorklogStrategy.RetainRemainingEstimate; | ||
break; | ||
case WorkLogStrategy.SetValue: | ||
strategy = WorklogStrategy.NewRemainingEstimate; | ||
break; | ||
default: | ||
strategy = WorklogStrategy.RetainRemainingEstimate; | ||
break; | ||
} | ||
|
||
issue.AddWorklog(worklog, strategy, remaining); | ||
} | ||
|
||
public void AssignIssue(string issueRef, string userName) | ||
{ | ||
var issue = client.GetIssue(issueRef); | ||
issue.Assignee = userName; | ||
issue.SaveChanges(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
RestSharp | ||
RestSharp | ||
Atlassian.SDK |
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
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
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
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
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
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
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
Oops, something went wrong.