gpt4 book ai didi

c# - 使用 C# Rally RestApi 添加和更新 Rally 项目变更集

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:47 27 4
gpt4 key购买 nike

我们是一家使用 C#、Team Foundation Server 和 Rally 作为我们主要项目跟踪的商店。

我们想使用 Rally Item ChangeSets 来遵循 TFS Changesets。使用 Rally 的 C# RestApi 似乎与用 Java 制作的有点不同。

有没有一种方法可以使用 Rally C# RestApi 完成与本文所述相同的事情? Rally update Changeset data from Java using Java Toolkit for Rally REST API

最佳答案

您绝对可以在 .NET 中执行相同的操作。一个好处是它比 Java 的等价物要简洁得多。这是一个例子:

// System Libraries
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Web;

// Rally REST API Libraries
using Rally.RestApi;
using Rally.RestApi.Response;

namespace RestExample_AddChangesetToUserStory
{
class Program
{
static void Main(string[] args)
{
// Set user parameters
String userName = "user@company.com";
String userPassword = "topsecret";

// Set Rally parameters
String rallyURL = "https://rally1.rallydev.com";
String rallyWSAPIVersion = "1.40";

//Initialize the REST API
RallyRestApi restApi;
restApi = new RallyRestApi(userName,
userPassword,
rallyURL,
rallyWSAPIVersion);

// Changeset Owner Username
String changesetOwner = "scm_integration@company.com";

// SCM Repository Name
String scmRepositoryName = "MySCMRepo";

// FormattedID of Artifact to associate to
String storyFormattedID = "US14";

// Create Request for User
Request userRequest = new Request("user");
userRequest.Fetch = new List<string>()
{
"UserName",
"Subscription",
"DisplayName"
};

// Add a Query to the Request
userRequest.Query = new Query("UserName", Query.Operator.Equals, changesetOwner);

// Query Rally
QueryResult queryUserResults = restApi.Query(userRequest);

// Grab resulting User object and Ref
DynamicJsonObject myUser = new DynamicJsonObject();
myUser = queryUserResults.Results.First();
String myUserRef = myUser["_ref"];

//Set our Workspace and Project scopings
String workspaceRef = "/workspace/12345678910";
String projectRef = "/project/12345678911";
bool projectScopingUp = false;
bool projectScopingDown = true;

// Get handle to SCM Repository
Request scmRequest = new Request("SCMRepository");
scmRequest.Fetch = new List<string>()
{
"ObjectID",
"Name",
"SCMType"
};

// Add query
scmRequest.Query = new Query("Name", Query.Operator.Equals, scmRepositoryName);

// Query Rally
QueryResult querySCMResults = restApi.Query(scmRequest);
DynamicJsonObject myRepository = new DynamicJsonObject();
myRepository = querySCMResults.Results.First();

// Find User Story that we want to add Changeset to

// Tee up Story Request
Request storyRequest = new Request("hierarchicalrequirement");
storyRequest.Workspace = workspaceRef;
storyRequest.Project = projectRef;
storyRequest.ProjectScopeDown = projectScopingDown;
storyRequest.ProjectScopeUp = projectScopingUp;

// Fields to Fetch
storyRequest.Fetch = new List<string>()
{
"Name",
"FormattedID",
"Changesets"
};

// Add a query
storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, storyFormattedID);

// Query Rally for the Story
QueryResult queryResult = restApi.Query(storyRequest);

// Pull reference off of Story fetch
var storyObject = queryResult.Results.First();
String storyReference = storyObject["_ref"];

// Pull existing Changesets off of Story
var existingChangesets = storyObject["Changesets"];

Console.WriteLine("Story: " + storyFormattedID);
Console.WriteLine("Number of Existing Changesets: " + existingChangesets.Count);

// DynamicJSONObject for New Changeset
DynamicJsonObject newChangeset = new DynamicJsonObject();

// Commit Time Stamp
String commitTimeStamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");

// Populate Changeset Attributes
newChangeset["SCMRepository"] = myRepository;
newChangeset["Author"] = myUserRef;
newChangeset["Revision"] = "2451";
newChangeset["Uri"] = "https://svnrepo.company.com:8001";
newChangeset["CommitTimestamp"] = commitTimeStamp;

// Artifacts list
var changeSetArtifacts = new ArrayList();
changeSetArtifacts.Add(storyObject);

// Update attribute on Changeset
newChangeset["Artifacts"] = changeSetArtifacts;


try
{
// Create the Changeset
Console.WriteLine("Creating Rally Changeset...");
CreateResult myChangesetCreateResult = restApi.Create("ChangeSet", newChangeset);
String myChangesetRef = myChangesetCreateResult.Reference;
Console.WriteLine("Successfully Created Rally Changeset: " + myChangesetRef);

List<string> createWarnings = myChangesetCreateResult.Warnings;
for (int i = 0; i < createWarnings.Count; i++)
{
Console.WriteLine(createWarnings[i]);
}

List<string> createErrors = myChangesetCreateResult.Errors;
for (int i = 0; i < createErrors.Count; i++)
{
Console.WriteLine(createErrors[i]);
}

}
catch (Exception e)
{
Console.WriteLine("Exception occurred creating Rally Changeset: " + e.StackTrace);
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
}

关于c# - 使用 C# Rally RestApi 添加和更新 Rally 项目变更集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692850/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com