Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProfileService: read profiles from client data repo #661

Merged
merged 43 commits into from
Apr 19, 2021
Merged

ProfileService: read profiles from client data repo #661

merged 43 commits into from
Apr 19, 2021

Conversation

seanlowjk
Copy link
Contributor

@seanlowjk seanlowjk commented Mar 20, 2021

Summary

This PR fixes #641

Description

Every time we need to update the dropdown list of sessions for our CATcher application, we would need to edit the environment.*.ts files. As a result, it becomes pretty troublesome just to create a new commit just for it.

As a result, we can make use of simple HTTP requests to get the relevant profiles from an external repository, such as CATcher-org/client_data to help us retrieve the relevant profiles needed.

Thus, we will only have one single source of truth where updating of custom profiles can be done in CATcher-org/client_data.

To Dos:

  • Fix e2e tests with regards to session selection

Suggested Commit Message

ProfileService: read profiles from client data repo

The app's default profiles are stored within the
codebase (in the AppConfig). Hence, updating the profiles
requires us to release / re-deploy a new version of CATcher.

Let's fetch the profiles from a client data repository instead.
This makes it possible to update the profiles
without modifying our codebase.

We can define a new ProfileService that uses a HTTP request
to fetch these profiles from the repo.

@codecov-io
Copy link

codecov-io commented Mar 20, 2021

Codecov Report

Merging #661 (ec7b2e3) into master (f005ee5) will increase coverage by 0.49%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #661      +/-   ##
==========================================
+ Coverage   68.67%   69.17%   +0.49%     
==========================================
  Files          75       76       +1     
  Lines        2273     2290      +17     
  Branches      208      209       +1     
==========================================
+ Hits         1561     1584      +23     
+ Misses        667      660       -7     
- Partials       45       46       +1     
Impacted Files Coverage Δ
src/environments/environment.gen.ts 83.33% <ø> (ø)
src/app/core/services/profile.service.ts 92.85% <92.85%> (ø)
src/app/core/services/github.service.ts 36.41% <100.00%> (+4.65%) ⬆️
src/app/shared/issue-tables/issue-sorter.ts 44.00% <0.00%> (-4.00%) ⬇️
...rc/app/shared/issue/assignee/assignee.component.ts 91.42% <0.00%> (ø)
...github/cache-manager/issues-cache-manager.model.ts 43.75% <0.00%> (+6.25%) ⬆️
...cache-manager/issue-last-modified-manager.model.ts 66.66% <0.00%> (+11.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f005ee5...ec7b2e3. Read the comment docs.

@seanlowjk seanlowjk requested a review from a team March 21, 2021 04:00
@seanlowjk seanlowjk marked this pull request as ready for review March 21, 2021 04:01
Copy link
Contributor

@dingyuchen dingyuchen left a comment

Choose a reason for hiding this comment

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

LGTM! just 1 small comment

Comment on lines 96 to 97
private fetchProfilesJson(): Promise<any> {
return fetch(AppConfig.clientDataUrl).then(res => res.json());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private fetchProfilesJson(): Promise<any> {
return fetch(AppConfig.clientDataUrl).then(res => res.json());
private fetchProfilesJson(): Promise<Profile[]> {
return fetch(AppConfig.clientDataUrl).then(res => res.json().profiles || []);

I think can include some error handling here and specify the promise type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me! 👍

@anubh-v anubh-v added this to the V3.3.8 milestone Mar 28, 2021
Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 Nice work with this.

Woops sorry, spotted a small bug

Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

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

Just one minor bug but otherwise LGTM! 👍

src/app/auth/profiles/profiles.component.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ptvrajsk ptvrajsk left a comment

Choose a reason for hiding this comment

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

Great! LGTM 👍

src/app/auth/profiles/profiles.component.ts Show resolved Hide resolved
@ptvrajsk ptvrajsk requested a review from anubh-v March 29, 2021 15:46
@seanlowjk
Copy link
Contributor Author

  1. Add GitHubService as a dependency to ProfileService. Within fetchExternalProfiles, invoke githubService.getProfilesData(). In the production GitHubService's getProfilesData method, fetch the profiles' data from the external repo. In the MockGitHubService's getProfilesData method, return a hardcoded profile.

I honestly feel that this is the best way to go about with respect to making sure our e2e tests passing offline.

  1. is a bit too hardcoded and if we need to add more other methods for ProfileService to fetch data related to profiles, we need to add more hardcoded logic which shouldn't be advisable.

@anubh-v
Copy link
Contributor

anubh-v commented Apr 10, 2021

Add GitHubService as a dependency to ProfileService. Within fetchExternalProfiles, invoke githubService.getProfilesData(). In the production GitHubService's getProfilesData method, fetch the profiles' data from the external repo. In the MockGitHubService's getProfilesData method, return a hardcoded profile.

I honestly feel that this is the best way to go about with respect to making sure our e2e tests passing offline.

  1. is a bit too hardcoded and if we need to add more other methods for ProfileService to fetch data related to profiles, we need to add more hardcoded logic which shouldn't be advisable.

Ok, let's go with the second approach. We can move fetch(AppConfig.clientDataUrl) into a method in GithubService.

tests/services/profile.service.spec.ts Outdated Show resolved Hide resolved
src/app/auth/profiles/profiles.component.ts Outdated Show resolved Hide resolved
@seanlowjk seanlowjk requested a review from anubh-v April 10, 2021 16:47
Copy link
Contributor

@anubh-v anubh-v left a comment

Choose a reason for hiding this comment

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

A few final comments

src/app/app.module.ts Outdated Show resolved Hide resolved
tests/services/profile.service.spec.ts Outdated Show resolved Hide resolved
tests/services/profile.service.spec.ts Outdated Show resolved Hide resolved
tests/services/profile.service.spec.ts Outdated Show resolved Hide resolved
src/app/auth/profiles/profiles.component.ts Outdated Show resolved Hide resolved
tests/services/profile.service.spec.ts Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2021

Codecov Report

Merging #661 (f05e769) into master (6a3c5e8) will increase coverage by 0.51%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #661      +/-   ##
==========================================
+ Coverage   69.08%   69.60%   +0.51%     
==========================================
  Files          76       77       +1     
  Lines        2274     2293      +19     
  Branches      208      209       +1     
==========================================
+ Hits         1571     1596      +25     
+ Misses        660      652       -8     
- Partials       43       45       +2     
Impacted Files Coverage Δ
src/environments/environment.gen.ts 83.33% <ø> (ø)
src/app/core/services/profile.service.ts 93.75% <93.75%> (ø)
src/app/core/services/github.service.ts 36.41% <100.00%> (+4.65%) ⬆️
src/app/shared/issue-tables/issue-sorter.ts 48.00% <0.00%> (-4.00%) ⬇️
...github/cache-manager/issues-cache-manager.model.ts 43.75% <0.00%> (+6.25%) ⬆️
...cache-manager/issue-last-modified-manager.model.ts 66.66% <0.00%> (+11.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a3c5e8...f05e769. Read the comment docs.

src/app/app.module.ts Outdated Show resolved Hide resolved
@anubh-v anubh-v changed the title ProfileService: Read Profiles From External Repository, Add Tests ProfileService: read profiles from external repository Apr 19, 2021
@anubh-v anubh-v changed the title ProfileService: read profiles from external repository ProfileService: read profiles from client data repo Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Read Profiles from External Repository
6 participants