Skip to content
Snippets Groups Projects
Commit 7410d83a authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

update: Add call to generate full repo name to GH validation helper

parent a86c50b1
No related branches found
No related tags found
1 merge request!211fix: update GH API requests to handle rest client param encoding
Pipeline #58474 passed
......@@ -108,7 +108,7 @@ public class GithubValidationHelper {
public ValidationResponse validateIncomingRequest(RequestWrapper wrapper, String org, String repoName, Integer prNo,
boolean forceRevalidation) {
// use logging helper to sanitize newlines as they aren't needed here
String fullRepoName = TransformationHelper.formatLog(org + '/' + repoName);
String fullRepoName = getFullRepoName(org, repoName);
// get the installation ID for the given repo if it exists, and if the PR noted exists
String installationId = ghAppService.getInstallationForRepo(org, repoName);
Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, org, repoName, prNo);
......@@ -297,7 +297,7 @@ public class GithubValidationHelper {
*/
public GithubWebhookTracking updateGithubTrackingIfMissing(RequestWrapper wrapper, Optional<GithubWebhookTracking> tracking,
PullRequest request, String installationId, String orgName, String repositoryName) {
String fullRepoName = TransformationHelper.formatLog(orgName + '/' + repositoryName);
String fullRepoName = getFullRepoName(orgName, repositoryName);
// if there is no tracking present, create the missing tracking and persist it
GithubWebhookTracking updatedTracking;
if (tracking.isEmpty()) {
......@@ -344,7 +344,7 @@ public class GithubValidationHelper {
public Optional<GithubWebhookTracking> getExistingRequestInformation(RequestWrapper wrapper, String installationId, String orgName,
String repositoryName, int pullRequestNumber) {
checkRequestParameters(installationId, orgName, repositoryName, pullRequestNumber);
String repositoryFullName = TransformationHelper.formatLog(orgName + '/' + repositoryName);
String repositoryFullName = getFullRepoName(orgName, repositoryName);
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
params.add(GitEcaParameterNames.INSTALLATION_ID_RAW, installationId);
params.add(GitEcaParameterNames.REPOSITORY_FULL_NAME_RAW, repositoryFullName);
......@@ -435,5 +435,16 @@ public class GithubValidationHelper {
throw new BadRequestException("Missing fields in order to prepare request: " + StringUtils.join(missingFields, ' '));
}
}
/**
* Retrieves the full repo name for a given org and repo name, used for storage and legacy support.
*
* @param org organization name being targeted
* @param repo name of repo being targeted
* @return the full repo name, following format of org/repo
*/
public static String getFullRepoName(String org, String repo) {
return TransformationHelper.formatLog(org + '/' + repo);
}
}
......@@ -26,7 +26,6 @@ import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames;
import org.eclipsefoundation.git.eca.namespace.HCaptchaErrorCodes;
import org.eclipsefoundation.git.eca.namespace.WebhookHeaders;
import org.eclipsefoundation.git.eca.service.GithubApplicationService;
import org.eclipsefoundation.utils.helper.TransformationHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -134,7 +133,7 @@ public class GithubWebhooksResource extends CommonResource {
@QueryParam(GitEcaParameterNames.INSTALLATION_ID_RAW) String installationId,
@QueryParam(GitEcaParameterNames.PULL_REQUEST_NUMBER_RAW) Integer prNo,
@FormParam("h-captcha-response") String captchaResponse) {
String sanitizedRepoName = TransformationHelper.formatLog(orgName + '/' + repoName);
String sanitizedRepoName = GithubValidationHelper.getFullRepoName(orgName, repoName);
// retrieve and check that the PR exists
Optional<PullRequest> prResponse = ghAppService.getPullRequest(installationId, orgName, repoName, prNo);
if (prResponse.isEmpty()) {
......
......@@ -28,6 +28,7 @@ import org.eclipsefoundation.git.eca.api.GithubAPI;
import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest;
import org.eclipsefoundation.git.eca.config.WebhooksConfig;
import org.eclipsefoundation.git.eca.dto.GithubApplicationInstallation;
import org.eclipsefoundation.git.eca.helper.GithubValidationHelper;
import org.eclipsefoundation.git.eca.helper.JwtHelper;
import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames;
import org.eclipsefoundation.git.eca.service.GithubApplicationService;
......@@ -37,7 +38,6 @@ import org.eclipsefoundation.http.model.RequestWrapper;
import org.eclipsefoundation.persistence.dao.PersistenceDao;
import org.eclipsefoundation.persistence.model.RDBMSQuery;
import org.eclipsefoundation.persistence.service.FilterService;
import org.eclipsefoundation.utils.helper.TransformationHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -118,7 +118,7 @@ public class DefaultGithubApplicationService implements GithubApplicationService
@Override
public Optional<PullRequest> getPullRequest(String installationId, String org, String repoName, Integer pullRequest) {
String fullRepoName = TransformationHelper.formatLog(org + '/' + repoName);
String fullRepoName = GithubValidationHelper.getFullRepoName(org, repoName);
return cache
.get(fullRepoName, new MultivaluedHashMap<>(), PullRequest.class,
() -> gh.getPullRequest(jwt.getGhBearerString(installationId), apiVersion, org, repoName, pullRequest))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment