Exemplo n.º 1
0
        public async Task <string> CreateIssue(YouTrackSharp.Connection _connection, string projectId, string summary, string description)
        {
            if (string.IsNullOrEmpty(projectId))
            {
                throw new ArgumentNullException(nameof(projectId));
            }

            var json = new JsonIssue();

            json.project.id  = projectId;
            json.summary     = summary;
            json.description = description;

            var client = await _connection.GetAuthenticatedHttpClient();

            var content  = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json");
            var response = await client.PostAsync($"api/issues?fields=idReadable", content);

            response.EnsureSuccessStatusCode();

            var resp    = JsonConvert.DeserializeObject <JsonIssue>(await response.Content.ReadAsStringAsync());
            var issueId = resp.idReadable;

            var uri = new Uri(new Uri(Properties.Settings.Default.baseUrl), "issue/" + issueId).ToString();

            //System.Diagnostics.Process.Start(uri);
            System.Diagnostics.Process.Start("chrome.exe", uri);

            return(issueId);
        }
Exemplo n.º 2
0
        public async Task <string> GetProjectId(YouTrackSharp.Connection connection, string projectName)
        {
            var client = await connection.GetAuthenticatedHttpClient();

            var query    = "api/admin/projects?fields=id,name,shortName&query=" + WebUtility.UrlEncode(projectName);
            var response = await client.GetAsync(query);

            if (response.IsSuccessStatusCode)
            {
                List <JsonProject> projs;
                try
                {
                    projs = JsonConvert.DeserializeObject <List <JsonProject> >(await response.Content.ReadAsStringAsync());
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error parsing project\n" + await response.Content.ReadAsStringAsync());
                }
                if (projs.Count == 1)
                {
                    return(projs[0].id);
                }
                throw new ApplicationException("Unable to find unique project matching \"" + projectName + "\". Server returned " + projs.Count + " projects.");
            }
            else
            {
                throw new ApplicationException("Query \"" + query + "\" failed with code " + response.StatusCode + " and message:\n" + response.Content.ReadAsStringAsync().Result);
            }
        }