microsoft / vsts-work-item-migrator

WiMigrator is a command line tool for migrating work items between VSTS/TFS projects
MIT License
148 stars 69 forks source link

Troubleshooting Missing Attachments on Migration #58

Closed devandanger closed 5 years ago

devandanger commented 5 years ago

Running this on a Mac everything seems to be be migrating well except for the attachments.

In WorkItemTrackingHelpers.cs

The following code is getting hit. I keep getting stuck around line 136 in which I'm getting a 400 bad request, unfortunately I can't figure out how to get a good return from this service.

        public async static Task<AttachmentReference> CreateAttachmentChunkedAsync(WorkItemTrackingHttpClient client, VssConnection connection, MemoryStream uploadStream, int chunkSizeInBytes)
        {
            // it's possible for the attachment to be empty, if so we can't used the chunked upload and need
            // to fallback to the normal upload path.
            if (uploadStream.Length == 0)
            {
                return await CreateAttachmentAsync(client, uploadStream);
            }

            var requestSettings = new VssHttpRequestSettings
            {
                SendTimeout = TimeSpan.FromMinutes(5)
            };
            var httpClient = new HttpClient(new VssHttpMessageHandler(connection.Credentials, requestSettings));

            // first create the attachment reference.  
            // can't use the WorkItemTrackingHttpClient since it expects either a file or a stream.
            var attachmentReference = await RetryHelper.RetryAsync(async () =>
            {
                var request = new HttpRequestMessage(HttpMethod.Post, $"{connection.Uri}/_apis/wit/attachments?uploadType=chunked&api-version=3.2");
                var response = await httpClient.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    return await response.Content.ReadAsAsync<AttachmentReference>();
                }
                else
                {
                    var exceptionResponse = await response.Content.ReadAsAsync<ExceptionResponse>();
                    throw new Exception(exceptionResponse.Message);
                }
            }, 5);

Further more I can't find the documentation for this api-version (current set to 3.2) to support this problem. Is it even necessary to create reference for these attachments any more?

obvioussean commented 5 years ago

@devandanger Could you use a fiddler equivalent for Mac and capture the full request/response that is failing?

devandanger commented 5 years ago

Having issues with getting Charles proxy working on the work machine... too many proxies going on. Working on a couple extensions which output to curl commands. Regardless my co-worker got it to magically work, so we'll see maybe it's somehow a network issue. More to follow.

devandanger commented 5 years ago

Very weird could get it to work on other machines.
Tried to log several diagnostics in order to solve this in lieu of a proper proxy tool working.

I tried this on a PC VM that I setup and this worked fine. Tried it on a coworkers Mac and it worked as well.

I'm moving on here but in case this gets re-opened.