Skip to content

Refactor: split issue and pull request logic for improved clarity#499

Open
TobyCyan wants to merge 26 commits intoCATcher-org:mainfrom
TobyCyan:464-refactor-split-issue-and-pr
Open

Refactor: split issue and pull request logic for improved clarity#499
TobyCyan wants to merge 26 commits intoCATcher-org:mainfrom
TobyCyan:464-refactor-split-issue-and-pr

Conversation

@TobyCyan
Copy link
Copy Markdown

Summary:

Fixes #464

Type of change:

  • 🎨 Code Refactoring

Changes Made:

  • Split Issue and PullRequest to extend from a base abstract RepoItem class.
  • Changed naming in multiple scripts to use RepoItem instead of Issue.
  • Rename files & folders to use repo-item.

Proposed Commit Message:

Refactor split issue and pull request models

Issues and pull requests are differentiated by a IssueOrPr field
in `issue.model.ts`.

This causes confusion and lack of clarity as a developer
working on parts of the codebase that deal with both.

Let's,
* introduce a base model for both issue and pull request models.
* update scripts and components to accept the new base class where 
applicable.
* rename related files and folders to follow the updated structure.

This makes the code more extensible in the future for
addition of other repository items and improves clarity
to whether an issue or pull request is expected.

Checklist:

  • I have tested my changes thoroughly.
  • I have created tests for any new code files created in this PR or provided a link to a issue/PR that addresses this.
  • I have added or modified code comments to improve code readability where necessary.
  • I have updated the project's documentation as necessary.

Copy link
Copy Markdown
Contributor

@SAN-MUYUN SAN-MUYUN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for refactoring such a large codebase, really appreciate the effort.
You may want to take a look at the suggestions regarding naming convention and some encapsulation issues.

this.milestone = githubIssue.milestone ? new Milestone(githubIssue.milestone) : Milestone.PRWithoutMilestone;
}

public static createPhaseBugReportingPullRequest(githubIssue: GithubIssue): RepoItem {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method createPhaseBugReportingPullRequest is taken from another project CATcher, which consists of a Bug Reporting Phase, hence the method name makes sense. Since this PR refactors the Issue class, will it be possible to change the name of this method to something more relevant to WATcher? Maybe createPullRequest will be better?
Same for the createPhaseBugReportingIssue above.

} else if (this.repoItem instanceof PullRequest && this.repoItem.state === 'CLOSED') {
return 'border-red';
} else if (this.issue.issueOrPr === 'Issue' && this.issue.stateReason === 'NOT_PLANNED') {
} else if (this.repoItem instanceof Issue && this.repoItem.stateReason === 'NOT_PLANNED') {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When checking for the type of repoItem, whether it is an Issue or PullRequest object, would it be better if you call the isPullRequest method provided below?
It would be even better if you can implement a method to get the type, or maybe adding a readonly field to each class would do job. Using instanceof to check for the type of repoItem somewhat defeats the purpose of refactoring the codebase in my opinion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your views, updated the PR 😸 !

this.prCount = data.filter((issue) => issue.issueOrPr === 'PullRequest').length;
data = applySearchFilter(this.filter.title, this.displayedColumn, this.repoItemService, data);
this.issueCount = data.filter((datum) => datum instanceof Issue).length;
this.prCount = data.filter((datum) => datum instanceof PullRequest).length;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor codebase to split Issue and PullRequest

3 participants