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

Is it necessary to compare before and after CHANGES_REQUESTED and APPROVED in getApproveTime? #28

Closed
kawamura-lvgs opened this issue Feb 7, 2024 · 3 comments · Fixed by #29

Comments

@kawamura-lvgs
Copy link

Hello, I have a question regarding the implementation of getApproveTime.

In the implementation of getApproveTime, it looks like this:
https://github.com/AlexSim93/pull-request-analytics-action/blob/master/src/converters/utils/calculations/getApproveTime.ts

import { makeComplexRequest } from "../../../requests";

export const getApproveTime = (
  reviews: Awaited<ReturnType<typeof makeComplexRequest>>["reviews"][number]
) => {
  const reviewChangesRequested = reviews?.reduce((acc, review) => {
    if (review.state === "CHANGES_REQUESTED") {
      const login = review.user?.login || "invalid";
      return { ...acc, [login]: true };
    }
    return acc;
  }, {}) as Record<string, boolean> | undefined;
  const reviewApproved = reviews?.reduce((acc, review) => {
    if (review.state === "APPROVED") {
      const login = review.user?.login || "invalid";
      return { ...acc, [login]: review.submitted_at };
    }
    return acc;
  }, {}) as Record<string, string> | undefined;
  const usersRequestedChanges = reviewChangesRequested
    ? Object.keys(reviewChangesRequested)
    : [];
  if (usersRequestedChanges.length === 0) {
    return reviews?.find((review) => review.state === "APPROVED")?.submitted_at;
  }

  const approveEntry = Object.entries(reviewApproved || {}).find(([user]) => {
    if (reviewChangesRequested?.[user]) {
      reviewChangesRequested[user] = false;

      return !Object.values(reviewChangesRequested).some(
        (value) => value === true
      );
    }
    return false;
  });

  return approveEntry?.[1];
};

In the current implementation, there is no comparison before and after CHANGES_REQUESTED and APPROVED.

Therefore, even if CHANGES_REQUESTED is performed after APPROVED, the value of approveEntry can still be obtained.
The data I want to obtain should ideally be in the state where all reviews are APPROVED, but this implementation does not achieve that.

Was this implementation intentional?
Your feedback would be appreciated.

@AlexSim93
Copy link
Owner

Hello, probably there is a bug. I wanted to implement it as you said. I will check and fix it.

@AlexSim93 AlexSim93 linked a pull request Feb 7, 2024 that will close this issue
9 tasks
@AlexSim93 AlexSim93 removed a link to a pull request Feb 7, 2024
9 tasks
@AlexSim93 AlexSim93 mentioned this issue Feb 7, 2024
9 tasks
@AlexSim93
Copy link
Owner

If you have multiple reviewers(one just commented and second approved) then this PR will be considered as approved. Once Changes requested are dismissed it is considered as changes are not required.

@kawamura-lvgs
Copy link
Author

kawamura-lvgs commented Feb 8, 2024

Thank you!

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 a pull request may close this issue.

2 participants