Ejemplo n.º 1
0
        private AnotherJiraRestClient.JiraModel.Version AddOrGetExistingVersion(ProjectMeta projectMeta)
        {
            IEnumerable <AnotherJiraRestClient.JiraModel.Version> versions = GetVersions();

            if (versions.Any(v => v.name == _jiraOptions.AvailableFromVersion.ToString()))
            {
                _logger.Info("Version <{0}> already exists in Jira", _jiraOptions.AvailableFromVersion);
                return(versions.Single(v => v.name == _jiraOptions.AvailableFromVersion.ToString()));
            }

            // add the version
            _logger.Info("Adding version <{0}>", _jiraOptions.AvailableFromVersion);
            var client       = new JiraClient(Account);
            var addedVersion = client.CreateVersion(new NewVersion
            {
                description     = "Automatically added release version via TC on " + _dateTimeProvider.Now.ToShortDateString() + " " + _dateTimeProvider.Now.ToShortTimeString(),
                name            = _jiraOptions.AvailableFromVersion.ToString(),
                userStartDate   = _dateTimeProvider.Now.ToString("dd/MMM/yyyy"),
                userReleaseDate = _dateTimeProvider.Now.ToString("dd/MMM/yyyy"),
                project         = projectMeta.key,
                released        = true,
            });

            return(addedVersion);
        }
Ejemplo n.º 2
0
        public static bool IsProjectAccessible(ClaimsPrincipal principal, ProjectMeta projectMeta)
        {
            if (principal == null)
            {
                return(false);
            }

            var identity = principal.Identity;

            if (projectMeta.License.LicensingScheme == ProjectLicensingScheme.None)
            {
                return(true);
            }
            else if (identity.IsAuthenticated)
            {
                var isAdmin = principal.HasClaim(claim => claim.Type == Claims.IS_ADMIN && claim.Value == "true");

                var canAccessProject = principal.HasClaim(claim => claim.Type == Claims.CAN_ACCESS_PROJECT &&
                                                          claim.Value.Split(";").Any(current => current == projectMeta.Id));

                var canAccessGroup = principal.HasClaim(claim => claim.Type == Claims.CAN_ACCESS_GROUP &&
                                                        claim.Value.Split(";").Any(group => projectMeta.GroupMemberships.Contains(group)));

                return(isAdmin || canAccessProject || canAccessGroup);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private bool VerifyProjectKey(out ProjectMeta projectMeta)
        {
            var client = new JiraClient(Account);

            projectMeta = client.GetProjectMeta(_jiraOptions.ProjectKey);
            return(projectMeta != null);
        }
Ejemplo n.º 4
0
        public void CreateNewTab(string FileName, ProjectFile projectFile = null, bool PopulateTreeView = false)
        {
            if (!MainTabControl.TabPages.ContainsKey(FileName))
            {
                MainTabControl.TabPages.Add(new TabPage(FileName)
                {
                    Name = FileName, Tag = projectFile
                });
                MainTabControl.SuspendLayout();

                bool add = true;
                FastColoredTextBox workspace = FrostbyteCore.Workspace.CreateWorkspace();

                if (projectFile != null)
                {
                    try
                    {
                        workspace.Text = File.ReadAllText(projectFile.GetLocation(FrostbyteCore.MainForm.project));
                        add            = workspace.Text.Length == 0;

                        new Syntax(workspace, projectFile.getFileType());
                    }
                    catch { }
                }
                else
                {
                    new Syntax(workspace, FileType.UNKNOWN);
                }

                if (add && Properties.Settings.Default.TopFileComment.Length > 0)
                {
                    string      comment = Properties.Settings.Default.TopFileComment;
                    ProjectMeta meta    = new ProjectMeta(FrostbyteCore.MainForm.project, FileName);

                    foreach (string replace in meta.variables.Keys)
                    {
                        comment = comment.Replace(replace, meta.variables[replace]);
                    }

                    workspace.Text = comment + '\n' + workspace.Text;
                }

                MainTabControl.TabPages[FileName].Controls.Add(workspace);
                MainTabControl.ResumeLayout();
                MainTabControl.SelectTab(FileName);
            }
            else
            {
                MainTabControl.SelectedTab = MainTabControl.TabPages[FileName];
            }

            FrostbyteCore.MainForm.toolStripStatusLabel1.Text = FrostbyteCore.Tabs.MainTabControl.SelectedTab.Name;
            FrostbyteCore.MainForm.toolStripStatusLabel2.Text = "Current Length: " + FrostbyteCore.Workspace.GetActiveWorkspace().Text.Length.ToString();

            if (PopulateTreeView)
            {
                FrostbyteCore.TreeViewer.PopulateTreeView();
            }
        }
Ejemplo n.º 5
0
 private Project CreateProjectResponse(ProjectInfo project, ProjectMeta projectMeta)
 {
     return(new Project()
     {
         Id = project.Id,
         Contact = projectMeta.Contact,
         ProjectStart = project.ProjectStart,
         ProjectEnd = project.ProjectEnd,
         ShortDescription = projectMeta.ShortDescription,
         LongDescription = projectMeta.LongDescription,
         IsQualityControlled = projectMeta.IsQualityControlled,
         License = projectMeta.License,
         LogBook = projectMeta.Logbook
     });
 }
Ejemplo n.º 6
0
        public void DownloadIssues(List <AnotherJiraRestClient.JiraModel.Version> versions)
        {
            if (JiraClient != null)
            {
                listView.BeginUpdate();

                listView.Groups.Clear();
                listView.Columns.Clear();
                listView.Items.Clear();

                listView.View       = View.Details;
                listView.ShowGroups = true;

                listView.Columns.Add("Issue Key", "Issue Key");
                listView.Columns.Add("Summary", "Summary");

                foreach (AnotherJiraRestClient.JiraModel.Version v in versions)
                {
                    ProjectMeta projectMeta = JiraClient.GetProjectMetaById(v.projectId);

                    string        jql    = $"project = {v.projectId} AND fixVersion = {v.id}";
                    List <string> fields = new List <string>()
                    {
                        "summary"
                    };
                    Issues issues = JiraClient.GetIssuesByJql(jql, 0, 10000, fields);


                    ListViewGroup versionGroup = listView.Groups.Add(v.id, $"{projectMeta.name} - {v.name}");

                    foreach (Issue issue in issues.issues)
                    {
                        ListViewItem item = listView.Items.Add(issue.key);
                        item.SubItems.Add(issue.fields.summary);

                        item.Group = versionGroup;
                        item.Tag   = issue;
                    }
                }

                foreach (ColumnHeader header in listView.Columns)
                {
                    header.Width = -1;
                }

                listView.EndUpdate();
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            JiraClient client = Client(args);

            string projectKey          = args[3];
            string issueKey            = projectKey + "-" + args[4];
            string customFieldToUpdate = args[5];

            ProjectMeta projectMetaData    = client.GetProjectMeta(projectKey);
            Issue       issueWithAllFields = client.GetIssue(issueKey);

            // https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-edit-issues
            var updateIssue = new
            {
                fields = new { customfield_11421 = "1.0.0" }
            };

            client.UpdateIssueFields(issueKey, updateIssue);
        }
Ejemplo n.º 8
0
        public static bool IsProjectEditable(ClaimsPrincipal principal, ProjectMeta projectMeta)
        {
            if (principal == null)
            {
                return(false);
            }

            var identity = principal.Identity;

            if (identity.IsAuthenticated)
            {
                var isAdmin = principal.HasClaim(claim => claim.Type == Claims.IS_ADMIN && claim.Value == "true");

                var canEditProject = principal.HasClaim(claim => claim.Type == Claims.CAN_EDIT_PROJECT &&
                                                        claim.Value.Split(";").Any(current => current == projectMeta.Id));

                return(isAdmin || canEditProject);
            }

            return(false);
        }
Ejemplo n.º 9
0
        public static bool IsProjectVisible(ClaimsPrincipal principal, ProjectMeta projectMeta, bool isProjectAccessible)
        {
            var identity = principal.Identity;

            // 1. project is visible if user is admin (this check must come before 2.)
            if (identity.IsAuthenticated)
            {
                var isAdmin = principal.HasClaim(claim => claim.Type == Claims.IS_ADMIN && claim.Value == "true");

                if (isAdmin)
                {
                    return(true); // not "return isAdmin"!!
                }
            }

            // 2. test projects are hidden by default
            if (Constants.HiddenProjects.Contains(projectMeta.Id))
            {
                return(false);
            }

            // 3. other projects

            // project is hidden, addtional checks required
            if (projectMeta.IsHidden)
            {
                // ignore hidden property in case user has access to project
                return(isProjectAccessible);
            }

            // project is visible
            else
            {
                return(true);
            }
        }
Ejemplo n.º 10
0
        private bool UpdateResolvedTicketsToVersion(ProjectMeta projectMeta)
        {
            _logger.Info("Getting all versions which have the fix version of <{0}>", _jiraOptions.FixVersion);
            string allClosedTicketsWithoutAnAvailableVersion =
                $"project={projectMeta.key} and status in (Resolved, \"Under Test\", Closed, Done) and fixVersion = {_jiraOptions.FixVersion} order by key";

            var client = new JiraClient(Account);

            bool      moreExists = false;
            const int maxResults = 100;
            int       startAt    = 0;
            var       allIssues  = new List <Issue>();

            do
            {
                Issues issues = client.GetIssuesByJql(allClosedTicketsWithoutAnAvailableVersion, startAt, maxResults);
                allIssues.AddRange(issues.issues.Select(i => i));

                if (issues.issues.Count + startAt < issues.total)
                {
                    moreExists = true;
                    startAt   += issues.issues.Count;
                }
                else
                {
                    moreExists = false;
                }
            } while (moreExists);

            if (!allIssues.Any())
            {
                _logger.Info("No tickets found to update");
                return(true);
            }

            AnotherJiraRestClient.JiraModel.Version addedVersion = AddOrGetExistingVersion(projectMeta);

            _logger.Info(
                $"Found <{allIssues.Count}> issues for this release, will be updated to 'Available Version' <{addedVersion.name}>");

            var expando = new ExpandoObject();
            var asDict  = (IDictionary <string, object>)expando;

            asDict.Add(_jiraOptions.CustomFieldName, addedVersion);

            var updateIssue = new
            {
                fields = expando
            };

            foreach (var issue in allIssues)
            {
                _logger.Info($"Processing <{issue.key}>");

                var request = new RestRequest
                {
                    Resource = $"{ResourceUrls.IssueByKey(issue.key)}?fields={_jiraOptions.CustomFieldName}",
                    Method   = Method.GET
                };

                // TODO: custom logic to handle some version information specific to Promapp's needs
                var promappIssue = client.Execute <PromappReleaseIssue>(request, HttpStatusCode.OK);

                if (promappIssue.fields == null)
                {
                    throw new InvalidOperationException("Fields is empty, has the Jira API changed?");
                }

                bool updateVersion = false;
                AnotherJiraRestClient.JiraModel.Version customFieldVersion = promappIssue.fields.customfield_11520;
                if (customFieldVersion == null)
                {
                    updateVersion = true;
                }
                else
                {
                    // because versions can have an "_" now
                    string actualVersion = customFieldVersion.name;
                    if (!actualVersion.TrySeparateVersionAndProject(out Version stampedVersion, out string projectName))
                    {
                        throw new InvalidOperationException($"Couldn't parse custom field value for ticket <{issue.key}> of <{customFieldVersion.name}> to a version");
                    }

                    // e.g. we have moved from dev->staging
                    if (_jiraOptions.FixVersionObj >= Version.Parse("1.0.0.0") &&
                        stampedVersion < Version.Parse("1.0.0.0") &&
                        _jiraOptions.AvailableFromVersionObj >= Version.Parse("1.0.0"))
                    {
                        updateVersion = true;
                    }
                    else
                    {
                        _logger.Info($"Issue <{issue.key}> won't get updated as it is already stamped with version <{actualVersion}>");
                    }
                }

                if (updateVersion)
                {
                    _logger.Info($"Update issue <{issue.key}> with version <{_jiraOptions.AvailableFromVersion}>");
                    client.UpdateIssueFields(issue.key, updateIssue);
                }
            }
            return(true);
        }