-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into issue-30367-Implement…
…-Abandoned-Job-Detection-and-Recovery
- Loading branch information
Showing
20 changed files
with
752 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
dotCMS/src/main/java/com/dotcms/api/web/HttpServletRequestImpersonator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.