Skip to content

Allow specifying any attributes for relations #89

Open
@andersforsgren

Description

@andersforsgren

Problem: I want to create a relation between a Work Item and a Build, e.g. "Integrated in build". That is rather straightforward in the api itself: just add a relation with the url of the build. The problem is that to be accepted, the relation must have a name, e.g. "Integrated in build".

This is an example of what I want to do:

    var attrs = new Dictionary<string, object>
    {
        { "name", "Integrated in build" },
        { "comment", "This is a comment" }
    };
    wrapper.Relations.AddLink("ArtifactLink", buildUrl, attrs);

The current impl of Relations.AddLink and WorkItemRelationWrapper ctor looks like this, allowing only the comment attribute for a relation.

    // In WorkItemRelationWrapperCollection.cs: AddLink only takes single string comment parameter
    public void AddLink(string type, string url, string comment)
    {
        AddRelation(new WorkItemRelationWrapper(
            type,
            url,
            comment
        ));
    }  

   // Which calls into...

   // In WorkItemRelationWrapper.cs: 
   public WorkItemRelationWrapper(string type, string url, string comment)
   {
       _relation = new WorkItemRelation()
       {
           Rel = type,
           Url = url,
           Attributes = new Dictionary<string,object> { { "comment", comment } }
       };
   }

Later, the same filter is applied also at the WorkItemRelationWrapperCollection to make absolutely sure that no attributes other than comment can exist.

  _pivotWorkItem.Changes.Add(new JsonPatchOperation()
  {
        Operation = Operation.Add,
        Path = "/relations/-",
        Value = new RelationPatch
        {
             rel = item.Rel,
             url = item.Url,
             attributes = item.Attributes != null && item.Attributes.TryGetValue("comment", out object value)
                 ? new { comment = value }
                 : null
        }
  });

I propose an overload that accepts any attribute set, like so

   public void AddLink(string type, string url, Dictionary<string, object> attributes) 
   {
       AddRelation(new WorkItemRelationWrapper(
           type,
           url,
           attributes
       ));
   }

I have tested this and it seems to work perfectly. It's not clear however if the current limitation to only a comment attribute has a reason that would make this overload a bad idea to add.

I can make a PR addinig the new overload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions