Пример #1
0
        private async Task <JObject> BuildFieldsObjectFromIssueAsync(RemoteIssue remoteIssue, RemoteFieldValue[] remoteFields, CancellationToken token)
        {
            var issueWrapper       = new RemoteIssueWrapper(remoteIssue);
            var serializerSettings = await this.GetIssueSerializerSettingsAsync(token).ConfigureAwait(false);

            var issueJson = JsonConvert.SerializeObject(issueWrapper, serializerSettings);

            var fieldsJsonSerializerSettings = new JsonSerializerSettings()
            {
                DateParseHandling = DateParseHandling.None
            };

            var issueFields  = JsonConvert.DeserializeObject <JObject>(issueJson, fieldsJsonSerializerSettings)["fields"] as JObject;
            var updateFields = new JObject();

            foreach (var field in remoteFields)
            {
                var issueFieldName  = field.id;
                var issueFieldValue = issueFields[issueFieldName];

                if (issueFieldValue == null && issueFieldName.Equals("components", StringComparison.OrdinalIgnoreCase))
                {
                    // JIRA does not accept 'null' as a valid value for the 'components' field.
                    //   So if the components field has been cleared it must be set to empty array instead.
                    issueFieldValue = new JArray();
                }

                updateFields.Add(issueFieldName, issueFieldValue);
            }

            return(updateFields);
        }
Пример #2
0
        public Task <Issue> CreateIssueAsyc(Issue issue, CancellationToken token)
        {
            var remoteIssueWrapper = new RemoteIssueWrapper(issue.ToRemote(), issue.ParentIssueKey);

            return(this.ExecuteRequestAsync(Method.POST, "rest/api/2/issue", remoteIssueWrapper, token).ContinueWith(task =>
            {
                return this.GetIssueAsync((string)task.Result["key"], token);
            }).Unwrap());
        }
Пример #3
0
        public async Task <string> CreateIssueAsync(Issue issue, CancellationToken token = default(CancellationToken))
        {
            var remoteIssue = await issue.ToRemoteAsync(token).ConfigureAwait(false);

            var remoteIssueWrapper = new RemoteIssueWrapper(remoteIssue, issue.ParentIssueKey);
            var serializerSettings = await this.GetIssueSerializerSettingsAsync(token).ConfigureAwait(false);

            var requestBody = JsonConvert.SerializeObject(remoteIssueWrapper, serializerSettings);

            var result = await _jira.RestClient.ExecuteRequestAsync(Method.POST, "rest/api/2/issue", requestBody, token).ConfigureAwait(false);

            return((string)result["key"]);
        }
Пример #4
0
        private JObject BuildFieldsObjectFromIssue(RemoteIssue remoteIssue, RemoteFieldValue[] remoteFields)
        {
            var issueWrapper = new RemoteIssueWrapper(remoteIssue);
            var issueJson    = JsonConvert.SerializeObject(issueWrapper, this.GetSerializerSettings());
            var issueFields  = JObject.Parse(issueJson)["fields"] as JObject;
            var updateFields = new JObject();

            foreach (var field in remoteFields)
            {
                updateFields.Add(field.id, issueFields[field.id]);
            }

            return(updateFields);
        }