Example #1
0
 public JiraClientWrapper(IOptions <JiraSettings> jiraSettings)
 {
     _jiraClient = CreateRestClient(
         jiraSettings.Value.BaseAddress,
         jiraSettings.Value.User,
         jiraSettings.Value.Password);
 }
Example #2
0
        public static async Task <IEnumerable <JiraUser> > GetAllUsers(this Atlassian.Jira.Jira jira,
                                                                       IJiraContext jiraContext,
                                                                       CancellationToken token = default)
        {
            var  url         = "rest/api/2/user/assignable/multiProjectSearch";
            int  startAt     = 0;
            int  loaded      = 0;
            var  fullResult  = new List <JiraUser>();
            bool hasMoreData = false;

            do
            {
                var page = await jira.RestClient.ExecuteRequestAsync <IEnumerable <Atlassian.Jira.JiraUser> >(
                    Method.GET,
                    $"{url}?projectKeys={jiraContext.Project}&startAt={startAt}&maxResults={MaxUsersPerRequest}",
                    null,
                    token).ConfigureAwait(false);

                if (page == null)
                {
                    break;
                }

                var previousCount = fullResult.Count;
                fullResult.AddRange(page.Select(ToJiraUser));
                loaded = fullResult.Count - previousCount;

                startAt += loaded;
            } while (loaded >= MaxUsersPerRequest);

            return(fullResult);
        }
Example #3
0
        private async Task <bool> TestLogin()
        {
            Atlassian.Jira.Jira tempJira = Atlassian.Jira.Jira.CreateRestClient(Setting.Value.Jira_Link, Username.Text, Password.Text, new JiraRestClientSettings()
            {
                EnableRequestTrace = true
            });

            bool pass = false;

            tempJira.Issues.MaxIssuesPerRequest = 5; //Set the Max Issues per Request to 25
            IPagedQueryResult <Issue> issues = null; //Creates a variable to store the issues in outside the try-catch statement

            try
            {
                issues = await tempJira.Issues.GetIssuesFromJqlAsync("project = LAC"); //Attempt to pull the issues

                if (issues.Count() == 5)
                {
                    pass = true;
                }
            }
            catch
            {
                pass = false;
            }

            return(pass);
        }
Example #4
0
        /// <summary>
        /// Метод для подключения к Jira
        /// </summary>
        public Atlassian.Jira.Jira JiraLogin(string URL, string login, string APItoken)
        {
            Atlassian.Jira.Jira jiraLog = Atlassian.Jira.Jira.CreateRestClient(new Atlassian.Jira.Remote.JiraRestClient(URL, login, APItoken));
            var URLserv = jiraLog.ServerInfo.GetServerInfoAsync().Result.BaseUrl;

            return(jiraLog);
        }
Example #5
0
 public JiraSoapClient(string baseUrl, string username, string password)
 {
     this.username = username;
     client        = new Atlassian.Jira.Jira(baseUrl, username, password)
     {
         MaxIssuesPerRequest = 999
     };
 }
Example #6
0
        /// <summary>
        /// Creates a JIRA client with the given rest client implementation.
        /// </summary>
        /// <param name="restClient">Rest client to use.</param>
        /// <param name="cache">Cache to use.</param>
        public static Jira CreateRestClient(IJiraRestClient restClient)
        {
            var services = new ServiceLocator();
            var jira     = new Jira(services);

            ConfigureDefaultServices(services, jira, restClient);
            return(jira);
        }
 internal JiraNamedEntityCollection(string fieldName, Jira jira, string projectKey, IList <T> list)
     : base(list)
 {
     _fieldName    = fieldName;
     _jira         = jira;
     _projectKey   = projectKey;
     _originalList = new List <T>(list);
 }
Example #8
0
 public BacklogProvider(IOptions <AtlassianOptions> options)
 {
     _client = Jira.Jira.CreateRestClient(
         options.Value.Url,
         options.Value.Username,
         options.Value.Password
         );
 }
Example #9
0
        /// <summary>
        /// Creates a JIRA client with the given rest client implementation.
        /// </summary>
        /// <param name="jiraClient">Rest client to use.</param>
        /// <param name="credentials">Credentials to use.</param>
        /// <param name="cache">Cache to use.</param>
        public static Jira CreateRestClient(IJiraRestClient jiraClient, JiraCredentials credentials = null, JiraCache cache = null)
        {
            var services = new ServiceLocator();
            var jira     = new Jira(services, credentials, cache);

            ConfigureDefaultServices(services, jira, jiraClient);
            return(jira);
        }
Example #10
0
        protected override IEnumerable <JiraNamedEntity> GetEntities(Jira jira, string projectKey = null)
        {
            if (jira == null)
            {
                throw new ArgumentNullException("jira");
            }

            return(jira.GetIssueTypes(projectKey));
        }
Example #11
0
        public JiraRepository(IJiraContext jiraContext)
        {
            // RAII
            _jiraContext = jiraContext;

            _jira = Atlassian.Jira.Jira.CreateRestClient(
                jiraContext.Uri, jiraContext.Login, jiraContext.Password);

            _jira.Issues.MaxIssuesPerRequest = MaxIssuesPerRequest;
        }
Example #12
0
 public JiraSoapClient(string baseUrl, string username, string password)
 {
     this.username = username;
     client        = new Atlassian.Jira.Jira(baseUrl, username, password)
     {
         MaxIssuesPerRequest = 999
     };
     client.GetAccessToken();
     HasTempo = false;
 }
        /// <summary>
        /// Creates a new instance of a ProjectVersion.
        /// </summary>
        /// <param name="jira">The jira instance.</param>
        /// <param name="remoteVersion">The remote version.</param>
        public ProjectVersion(Jira jira, RemoteVersion remoteVersion)
            : base(remoteVersion)
        {
            if (jira == null)
            {
                throw new ArgumentNullException("jira");
            }

            _jira          = jira;
            _remoteVersion = remoteVersion;
        }
        public JiraAccessService(SyncSystemDTO syncSystem)
        {
            SyncSystem   = syncSystem;
            jiraUserName = syncSystem.SystemLogin;
            jiraPassword = syncSystem.SystemPassword;
            jiraApiUrl   = syncSystem.SystemApiUrl.Trim('/');
            JiraRestClientSettings jiraRestClientSettings = new JiraRestClientSettings();

            jiraRestClientSettings.CustomFieldSerializers.Remove("com.pyxis.greenhopper.jira:gh-sprint");
            JiraConnection = Atlassian.Jira.Jira.CreateRestClient(syncSystem.SystemUrl, jiraUserName, jiraPassword, jiraRestClientSettings);
        }
        /// <summary>
        /// Creates a new instance of an Attachment from a remote entity.
        /// </summary>
        /// <param name="jira">Object used to interact with JIRA.</param>
        /// <param name="remoteAttachment">Remote attachment entity.</param>
        public Attachment(Jira jira, RemoteAttachment remoteAttachment)
        {
            _jira = jira;

            AuthorUser  = remoteAttachment.authorUser;
            CreatedDate = remoteAttachment.created;
            FileName    = remoteAttachment.filename;
            MimeType    = remoteAttachment.mimetype;
            FileSize    = remoteAttachment.filesize;
            Id          = remoteAttachment.id;
        }
 /// <summary>
 /// Creates a new instance of an Attachment from a remote entity.
 /// </summary>
 /// <param name="jira">Object used to interact with JIRA.</param>
 /// <param name="webClient">WebClient to use to download attachment.</param>
 /// <param name="remoteAttachment">Remote attachment entity.</param>
 public Attachment(Jira jira, IWebClient webClient, RemoteAttachment remoteAttachment)
 {
     _jira      = jira;
     _author    = remoteAttachment.author;
     _created   = remoteAttachment.created;
     _fileName  = remoteAttachment.filename;
     _mimeType  = remoteAttachment.mimetype;
     _fileSize  = remoteAttachment.filesize;
     _id        = remoteAttachment.id;
     _webClient = webClient;
 }
Example #17
0
        internal JiraNamedEntity LoadByName(Jira jira, string projectKey)
        {
            var entity = GetEntities(jira, projectKey).FirstOrDefault(e => e.Name.Equals(_name, StringComparison.OrdinalIgnoreCase));

            if (entity != null)
            {
                _id   = entity._id;
                _name = entity._name;
            }
            return(this);
        }
 public static bool operator !=(ComparableString field, DateTime value)
 {
     if ((object)field == null)
     {
         return(value != null);
     }
     else
     {
         return(field.Value != Jira.FormatDateTimeString(value));
     }
 }
        private static void AddAuthenticationToRequest(IWebClient webClient, Jira jira)
        {
            var credentials = jira.GetCredentials();

            if (String.IsNullOrEmpty(credentials.UserName) || String.IsNullOrEmpty(credentials.Password))
            {
                throw new InvalidOperationException("Unable to download attachment, user and/or password are missing. You can specify a provider for credentials when constructing the Jira instance.");
            }

            webClient.AddQueryString("os_username", Uri.EscapeDataString(credentials.UserName));
            webClient.AddQueryString("os_password", Uri.EscapeDataString(credentials.Password));
        }
Example #20
0
        /// <summary>
        /// Creates a JIRA rest client.
        /// </summary>
        /// <param name="url">Url to the JIRA server.</param>
        /// <param name="username">Username used to authenticate.</param>
        /// <param name="password">Password used to authenticate.</param>
        /// <param name="settings">Settings to configure the rest client.</param>
        /// <returns>Jira object configured to use REST API.</returns>
        public static Jira CreateRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)
        {
            var services = new ServiceLocator();

            settings = settings ?? new JiraRestClientSettings();
            var jira       = new Jira(services, new JiraCredentials(username, password), settings.Cache);
            var restClient = new JiraRestClient(url, username, password, settings);

            ConfigureDefaultServices(services, jira, restClient);

            return(jira);
        }
 public static bool Login(string userName, string password)
 {
     try
     {
         jira = new Jira(JiraHelper.JIRA_PATH, userName, password);
         return(true);
     }
     catch
     {
         SetupHelper();
         return(false);
     }
 }
 public static bool Login(string userName, string password)
 {
     try
     {
         jira = new Jira(JiraHelper.JIRA_PATH, userName, password);
         return true;
     }
     catch
     {
         SetupHelper();
         return false;
     }
 }
Example #23
0
        /// <summary>
        /// Creates a JIRA client configured to use the REST API.
        /// </summary>
        /// <param name="url">Url to the JIRA server.</param>
        /// <param name="username">Username used to authenticate.</param>
        /// <param name="password">Password used to authenticate.</param>
        /// <param name="settings">Settings to configure the rest client.</param>
        /// <returns>Jira object configured to use REST API.</returns>
        public static Jira CreateRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)
        {
            Jira jira    = null;
            var  options = new JiraRestClient.Options()
            {
                Url                = url,
                Username           = username,
                Password           = password,
                RestClientSettings = settings ?? new JiraRestClientSettings(),
                GetCurrentJiraFunc = () => jira
            };

            var restClient = new JiraRestClient(options);

            jira = CreateRestClient(restClient, new JiraCredentials(username, password), options.RestClientSettings.Cache);

            return(jira);
        }
Example #24
0
 private static void ConfigureDefaultServices(ServiceLocator services, Jira jira, IJiraRestClient restClient)
 {
     services.Register <IProjectVersionService>(() => new ProjectVersionService(jira));
     services.Register <IProjectComponentService>(() => new ProjectComponentService(jira));
     services.Register <IIssuePriorityService>(() => new IssuePriorityService(jira));
     services.Register <IIssueResolutionService>(() => new IssueResolutionService(jira));
     services.Register <IIssueStatusService>(() => new IssueStatusService(jira));
     services.Register <IIssueLinkService>(() => new IssueLinkService(jira));
     services.Register <IIssueRemoteLinkService>(() => new IssueRemoteLinkService(jira));
     services.Register <IIssueTypeService>(() => new IssueTypeService(jira));
     services.Register <IIssueFilterService>(() => new IssueFilterService(jira));
     services.Register <IIssueFieldService>(() => new IssueFieldService(jira));
     services.Register <IIssueService>(() => new IssueService(jira, restClient.Settings));
     services.Register <IJiraUserService>(() => new JiraUserService(jira));
     services.Register <IJiraGroupService>(() => new JiraGroupService(jira));
     services.Register <IProjectService>(() => new ProjectService(jira));
     services.Register <IJqlExpressionVisitor>(() => new JqlExpressionVisitor());
     services.Register <IFileSystem>(() => new FileSystem());
     services.Register(() => restClient);
 }
Example #25
0
        private void Connect()
        {
            Log.Verbose("About to call Atlassian.Jira.Jira.CreateRestClient(). This does not connect to JIRA");
            jira = Atlassian.Jira.Jira.CreateRestClient(_rootUrl, _userName, _password, null);

            _token = jira.GetAccessToken();// Tokens are no longer used with REST. _token = "<Unused>"
            Log.Verbose("_token is {0}", _token);

            try
            {
                Log.Verbose("About to make an actual connection to JIRA to test out username and password.");
                foreach (var project in jira.GetProjects())
                {
                    Log.Verbose("Project = {0}.", project.Name);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new ApplicationException("Access denied: Connection issue. Possibly bad username or password.");
            }
        }
        /// <summary>
        /// Creates a new instance of IssueFields.
        /// </summary>
        /// <param name="remoteIssue">The remote issue that contains the fields.</param>
        /// <param name="jira">The Jira instance that owns the issue.</param>
        public IssueFields(RemoteIssue remoteIssue, Jira jira)
        {
            _map = remoteIssue.fieldsReadOnly ?? new Dictionary <string, JToken>();

            if (remoteIssue.remotePagedComments != null)
            {
                var pagedResults = remoteIssue.remotePagedComments;
                var comments     = pagedResults.remoteComments.Select(remoteComment => new Comment(remoteComment));
                this.Comments = new PagedQueryResult <Comment>(comments, pagedResults.startAt, pagedResults.maxResults, pagedResults.total);
            }

            if (remoteIssue.remotePagedWorklogs != null)
            {
                var pagedResults = remoteIssue.remotePagedWorklogs;
                var worklogs     = pagedResults.remoteWorklogs.Select(remoteWorklog => new Worklog(remoteWorklog));
                this.Worklogs = new PagedQueryResult <Worklog>(worklogs, pagedResults.startAt, pagedResults.maxResults, pagedResults.total);
            }

            if (remoteIssue.remoteAttachments != null)
            {
                this.Attachments = remoteIssue.remoteAttachments.Select(remoteAttachment => new Attachment(jira, remoteAttachment));
            }
        }
Example #27
0
 public JiraSoapClient(string baseUrl, string username, string password)
 {
     this.username = username;
     client = new Atlassian.Jira.Jira(baseUrl, username, password) { MaxIssuesPerRequest = 999 };
 }
        protected override async Task <IEnumerable <JiraNamedEntity> > GetEntitiesAsync(Jira jira, CancellationToken token)
        {
            var results = await jira.IssueTypes.GetIssueTypesAsync(token).ConfigureAwait(false);

            if (!String.IsNullOrEmpty(ProjectKey) &&
                (SearchByProjectOnly || results.Distinct(new JiraEntityNameEqualityComparer()).Count() != results.Count()))
            {
                // There are multiple issue types with the same name. Possibly because there are a combination
                //  of classic and NextGen projects in Jira. Get the issue types from the project if it is defined.
                results = await jira.IssueTypes.GetIssueTypesForProjectAsync(ProjectKey).ConfigureAwait(false);
            }

            return(results as IEnumerable <JiraNamedEntity>);
        }
 protected override IEnumerable <JiraNamedEntity> GetEntities(Jira jira, string projectKey = null)
 {
     return(jira.GetIssueStatuses());
 }
 internal IssueStatus(Jira jira, string id)
     : base(jira, id)
 {
 }
 public static void SetupHelper()
 {
     jira = new Jira(JiraHelper.JIRA_PATH, "warehouse", "warehouse");
     IsInitialized = true;
 }
Example #32
0
 public Jira(string serverAddress, string user, string password)
 {
     _instance = new Atlassian.Jira.Jira(serverAddress, user, password) {MaxIssuesPerRequest = 250};
 }
Example #33
0
 internal IssueType(Jira jira, string id)
     : base(jira, id)
 {
 }
Example #34
0
        protected override async Task <IEnumerable <JiraNamedEntity> > GetEntitiesAsync(Jira jira, CancellationToken token)
        {
            var results = await jira.Resolutions.GetResolutionsAsync(token).ConfigureAwait(false);

            return(results as IEnumerable <JiraNamedEntity>);
        }