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

mrc-5105: Add has_modifications flag to report list endpoint #3

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

r-ash
Copy link
Contributor

@r-ash r-ash commented Feb 29, 2024

To indicate when a particular report has modifications from the default branch.

We want this because in the UI when users view the list of reports, we want to have a checkbox to show only those reports which contain modifications (if the user has selected a branch other than the default branch)

This will always return has_modifications even if the hash this is called with the default branch or a hash which is on the default branch.

This gets the default branch from the gert::git_remote_info("origin"). This is the HEAD branch from the remote origin, which if I understand correctly should always be the GitHub default branch.

This gets the modified files using git diff <from>...<to> using the remote origin as the <from> branch. This is the same as what orderly.server is doing at the moment. I expect we could probably make an enhancement in gert to be able to call gert::git_diff() with a specified base ref but can do that later.

@r-ash r-ash changed the title Add has_modifications flag to response Add has_modifications flag to report list endpoint Feb 29, 2024
@r-ash r-ash requested review from richfitz and M-Kusumgar February 29, 2024 10:37
@@ -33,17 +33,24 @@ root <- function() {

##' @porcelain
##' GET /report/list => json(report_list)
##' query hash :: string
##' query ref :: string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this to ref too because I think this is better description, it can work with a hash or a branch name

@r-ash r-ash changed the title Add has_modifications flag to report list endpoint mrc-5105: Add has_modifications flag to report list endpoint Feb 29, 2024
Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ddd6c59) to head (c89423d).

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #3   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         6    +1     
  Lines           65       111   +46     
=========================================
+ Hits            65       111   +46     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

To indicate when a particular report has modifications from the default
branch
As this can take any ref, a hash, a branch name etc.
R/git.R Outdated
}


git_ref_to_sha <- function(ref, repo = NULL, check = FALSE) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this not gert::git_commit_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It absolutely is yes, thanks!

}


git_get_modified <- function(ref, base = NULL,
Copy link
Member

Choose a reason for hiding this comment

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

we should make a ticket to patch gert for this perhaps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

R/util_assert.R Outdated
i = "{name} has length {length(x)}"),
call = call, arg = arg)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

consider invisible return of x on all of these (not needed on assert_scalar_character as that's implicit) as that's often useful

@r-ash r-ash requested a review from richfitz March 1, 2024 17:31
R/util_assert.R Outdated
@@ -0,0 +1,25 @@
assert_scalar <- function(x, name = deparse(substitute(x)), arg = name,
Copy link
Member

Choose a reason for hiding this comment

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

After your change you no longer need these :) but they're bound to come in useful lter

test_that("assert_scalar", {
expect_error(assert_scalar(NULL), "must be a scalar")
expect_error(assert_scalar(numeric(0)), "must be a scalar")
expect_error(assert_scalar(1:2), "must be a scalar")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
expect_error(assert_scalar(1:2), "must be a scalar")
expect_error(assert_scalar(1:2), "must be a scalar")
expect_no_error(assert_scalar(1))

Copy link
Contributor

@M-Kusumgar M-Kusumgar left a comment

Choose a reason for hiding this comment

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

LGTM!

@r-ash r-ash merged commit abbf115 into main Mar 5, 2024
9 checks passed
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.

3 participants