Exemple #1
0
        async private static Task <User> getUserAsync(string username, Shortcuts shortcuts)
        {
            if (String.IsNullOrEmpty(username))
            {
                return(null);
            }

            GitLabClient.UserAccessor userAccessor = shortcuts.GetUserAccessor();
            return(await userAccessor.SearchUserByUsernameAsync(username)
                   ?? await userAccessor.SearchUserByNameAsync(username)); // fallback
        }
        async private Task initializeLabelListIfEmpty(string hostname)
        {
            if (ConfigurationHelper.GetUsersForHost(hostname, Program.Settings).Any())
            {
                return;
            }

            GitLabClient.UserAccessor userAccessor = _shortcuts.GetUserAccessor();

            bool migratedLabels = false;

            addOperationRecord("Preparing workflow to the first launch has started");
            List <Tuple <string, bool> > labels = new List <Tuple <string, bool> >();
            MergeRequestFilterState      filter = _mergeRequestFilter.Filter;

            if (filter.Enabled)
            {
                foreach (string keyword in filter.Keywords)
                {
                    string adjustedKeyword = keyword;
                    if (keyword.StartsWith(Constants.GitLabLabelPrefix) || keyword.StartsWith(Constants.AuthorLabelPrefix))
                    {
                        adjustedKeyword = keyword.Substring(1);
                    }
                    User user = await userAccessor.SearchUserByUsernameAsync(adjustedKeyword);

                    if (user != null)
                    {
                        if (!labels.Any(x => x.Item1 == user.Username))
                        {
                            labels.Add(new Tuple <string, bool>(user.Username, true));
                            migratedLabels |= true;
                        }
                    }
                }
            }

            User currentUser = await userAccessor.GetCurrentUserAsync();

            if (currentUser != null)
            {
                if (!labels.Any(x => x.Item1 == currentUser.Username))
                {
                    labels.Add(new Tuple <string, bool>(currentUser.Username, true));
                }
            }
            ConfigurationHelper.SetUsersForHost(hostname, labels, Program.Settings);
            updateUsersListView();
            addOperationRecord("Workflow has been prepared to the first launch");

            if (Program.Settings.ShowWarningOnFilterMigration)
            {
                if (migratedLabels)
                {
                    MessageBox.Show(
                        "By default, new versions of mrHelper select user-based workflow. "
                        + "Some of your filters are moved to Settings and only merge requests that match them are loaded from GitLab. "
                        + "You don't need to specify projects manually.\n"
                        + "Note that old Filter entry still works as additional filtering of loaded merge requests.",
                        "Important news",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    checkBoxDisplayFilter.Checked = false;
                }
                else if (currentUser != null)
                {
                    MessageBox.Show(
                        "By default, new versions of mrHelper select user-based workflow. "
                        + "Only merge requests that authored by you OR expected to be reviewed by you are loaded from GitLab.\n"
                        + "If you want to track merge requests of other users, specify them in Settings. ",
                        "Important news",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                Program.Settings.ShowWarningOnFilterMigration = false;
            }
        }