Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into issue-30367-Implement…
Browse files Browse the repository at this point in the history
…-Abandoned-Job-Detection-and-Recovery
  • Loading branch information
jgambarios committed Nov 20, 2024
2 parents 730d5f1 + f688ff8 commit 09f6462
Show file tree
Hide file tree
Showing 20 changed files with 752 additions and 182 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/issue_comp_release-labeling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: 'Release Labeling'
on:
workflow_call:
secrets:
CI_MACHINE_TOKEN:
description: 'CI machine token'
required: true
inputs:
rename_label:
description: 'Rename label'
type: string
required: false
default: 'Next Release'
new_label:
description: 'New label'
type: string
required: true
workflow_dispatch:
inputs:
rename_label:
description: 'Rename label'
type: string
required: false
default: 'Next Release'
new_label:
description: 'New label'
type: string
required: true

jobs:
release-labeling:
runs-on: ubuntu-20.04
env:
REPO: core
steps:
- run: echo 'GitHub context'
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Rename label
if: success()
id: validate-inputs
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function getLabel(name) {
console.log(`Getting label [${name}]`);
try {
const response = await github.rest.issues.getLabel({
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
name,
});
return response.data;
} catch(error) {
console.log(`Error getting label: ${error}`);
return undefined;
}
}
const renameLabel = await getLabel('${{ inputs.rename_label }}');
if (!renameLabel) {
console.log(`Label [${{ inputs.rename_label }}] not found, skipping rename`);
return;
}
const newLabel = await getLabel('${{ inputs.new_label }}');
if (newLabel) {
console.log(`Label [${newLabel.name}] already exists, skipping rename`);
return;
}
console.log(`Renaming label [${renameLabel.name}] for owner [${{ github.repository_owner }}] repo [${{ env.REPO }}] with new label [${{ inputs.new_label }}]`);
await github.rest.issues.updateLabel({
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
name: renameLabel.name,
new_name: '${{ inputs.new_label }}'
});
- name: Re-Create New Label
if: success()
uses: actions/github-script@v7
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function getLabel(name) {
console.log(`Getting label [${name}]`);
try {
const response = await github.rest.issues.getLabel({
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
name,
});
return response.data;
} catch(error) {
console.log(`Error getting label: ${error}`);
return undefined;
}
}
const renameLabel = await getLabel('${{ inputs.rename_label }}');
if (renameLabel) {
console.log(`Label [${renameLabel.name}] already exists, skipping re-creation`);
return;
}
console.log(`Recreating label [${{ inputs.rename_label }}] for owner [${{ github.repository_owner }}] repo [${{ env.REPO }}]`);
await github.rest.issues.createLabel({
owner: '${{ github.repository_owner }}',
repo: '${{ env.REPO }}',
name: '${{ inputs.rename_label }}'
});
33 changes: 7 additions & 26 deletions .github/workflows/legacy-release_maven-release-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,32 +395,13 @@ jobs:

- uses: ./.github/actions/core-cicd/cleanup-runner

# - name: Fetch `Next Release` issues
# id: fetch-next-release-issues
# uses: ./.github/actions/issues/issue-fetcher
# with:
# fetch_operation: 'WITH_LABELS'
# fetch_value: ${{ env.FETCH_VALUE }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
# if: github.event.inputs.update_github_labels == 'true'
#
# - name: Clear next release issues
# uses: ./.github/actions/issues/issue-labeler
# with:
# issues_json: ${{ steps.fetch-next-release-issues.outputs.issues }}
# labels: ${{ env.FETCH_VALUE }}
# operation: 'REMOVE'
# github_token: ${{ secrets.GITHUB_TOKEN }}
# if: github.event.inputs.update_github_labels == 'true'
#
# - name: Label current release issues
# uses: ./.github/actions/issues/issue-labeler
# with:
# issues_json: ${{ steps.fetch-next-release-issues.outputs.issues }}
# labels: 'Release ${{ needs.prepare-release.outputs.release_version }}'
# operation: 'ADD'
# github_token: ${{ secrets.GITHUB_TOKEN }}
# if: github.event.inputs.update_github_labels == 'true'
- name: Release Labeling
if: success() && github.event.inputs.update_github_labels == 'true'
uses: ./.github/workflows/issue_comp_release-labeling.yml
with:
new_label: 'Release ${{ github.event.inputs.release_version }}''
secrets:
CI_MACHINE_TOKEN: ${{ secrets.CI_MACHINE_TOKEN }}
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.dotcms.api.web;

import com.dotcms.mock.request.FakeHttpRequest;
import com.dotcms.mock.request.MockAttributeRequest;
import com.dotcms.mock.request.MockHeaderRequest;
import com.dotcms.mock.request.MockParameterRequest;
import com.dotcms.mock.request.MockSessionRequest;
import com.dotcms.mock.response.MockHttpResponse;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
* The Request impersonator is a class that will return a Mock instance of a request object.
* We use this to block the real request object from being used to perform operations that could break certain flows
* Sometimes we want to block a session invalidation for example or a redirect, so we use this class to return a fake request object.
*/
public class HttpServletRequestImpersonator {

private static final Pattern MOCK_OR_FAKE_PATTERN = Pattern.compile("(^|\\b|\\.)mock|fake($|\\b|\\.)", Pattern.CASE_INSENSITIVE);

/**
* new instance of {@link HttpServletRequestImpersonator}
* @return {@link HttpServletRequestImpersonator}
*/
public static HttpServletRequestImpersonator newInstance() {
return new HttpServletRequestImpersonator();
}

/**
* Returns a fake request object
* @return {@link HttpServletRequest}
*/
public HttpServletRequest request() {
final HttpServletRequest request = HttpServletRequestThreadLocal.INSTANCE.getRequest();
if (isMockRequest(request)) {
// no use in mocking a mock this could actually break tests
return request;
}
return request == null
? new FakeHttpRequest("localhost", "/").request()
: new MockHeaderRequest(new MockAttributeRequest(new MockSessionRequest(new MockParameterRequest(request))));
}

/**
* Returns a fake response object
* @return {@link HttpServletResponse}
*/
public HttpServletResponse response() {
return new MockHttpResponse();
}

/**
* Check if the request is a mock request
* as We have so many different types of mock requests this is probably the best way to check
* @param request {@link HttpServletRequest}
* @return boolean
*/
boolean isMockRequest(final HttpServletRequest request) {
if (request == null) {
return false;
}
final String clazzName = request.getClass().getName();
return MOCK_OR_FAKE_PATTERN.matcher(clazzName).find();
}

}
Loading

0 comments on commit 09f6462

Please sign in to comment.