mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-12-05 05:02:57 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41cf0afe47 | ||
|
|
b457f7bfef | ||
|
|
3ffccacd46 | ||
|
|
77d56500d9 |
No files matched your search
@@ -124,7 +124,7 @@ jobs:
|
|||||||
name: dist
|
name: dist
|
||||||
path: dist
|
path: dist
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
commit-message: 'build: update distribution'
|
commit-message: 'build: update distribution'
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ jobs:
|
|||||||
git config user.name actions-bot
|
git config user.name actions-bot
|
||||||
git config user.email actions-bot@users.noreply.github.com
|
git config user.email actions-bot@users.noreply.github.com
|
||||||
- name: Tag new target
|
- name: Tag new target
|
||||||
run: git tag -f "${INPUT_MAIN_VERSION}" "${INPUT_TARGET}"
|
run: |
|
||||||
|
sha=$(git rev-parse --verify --end-of-options "${INPUT_TARGET}^{commit}")
|
||||||
|
git tag -f "${INPUT_MAIN_VERSION}" "${sha}"
|
||||||
env:
|
env:
|
||||||
INPUT_MAIN_VERSION: ${{ github.event.inputs.main_version }}
|
INPUT_MAIN_VERSION: ${{ github.event.inputs.main_version }}
|
||||||
INPUT_TARGET: ${{ github.event.inputs.target }}
|
INPUT_TARGET: ${{ github.event.inputs.target }}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ const mockOctokit = {
|
|||||||
createBlob: jest.fn(),
|
createBlob: jest.fn(),
|
||||||
createTree: jest.fn(),
|
createTree: jest.fn(),
|
||||||
createCommit: jest.fn(),
|
createCommit: jest.fn(),
|
||||||
createRef: jest.fn()
|
createRef: jest.fn(),
|
||||||
|
getRef: jest.fn(),
|
||||||
|
updateRef: jest.fn()
|
||||||
},
|
},
|
||||||
repos: {
|
repos: {
|
||||||
getBranch: jest.fn()
|
getBranch: jest.fn()
|
||||||
@@ -38,8 +40,12 @@ function makeCommit(changes: Commit['changes']): Commit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('github-helper unit tests', () => {
|
describe('github-helper unit tests', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
test('pushSignedCommits deletes a removed submodule instead of pointing it at the null sha', async () => {
|
test('pushSignedCommits deletes a removed submodule instead of pointing it at the null sha', async () => {
|
||||||
const {git: gitApi, repos: reposApi} = mockOctokit.rest
|
const {git: gitApi} = mockOctokit.rest
|
||||||
gitApi.createBlob.mockResolvedValue({
|
gitApi.createBlob.mockResolvedValue({
|
||||||
data: {sha: 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'}
|
data: {sha: 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'}
|
||||||
})
|
})
|
||||||
@@ -54,7 +60,7 @@ describe('github-helper unit tests', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
gitApi.createRef.mockResolvedValue({})
|
gitApi.createRef.mockResolvedValue({})
|
||||||
reposApi.getBranch.mockRejectedValue(new Error('Branch not found'))
|
gitApi.getRef.mockRejectedValue(new Error('Not Found'))
|
||||||
const git = {
|
const git = {
|
||||||
showFileAtRefBase64: jest.fn().mockResolvedValue('Y29udGVudA==')
|
showFileAtRefBase64: jest.fn().mockResolvedValue('Y29udGVudA==')
|
||||||
}
|
}
|
||||||
@@ -115,4 +121,62 @@ describe('github-helper unit tests', () => {
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('pushSignedCommits creates the ref when the branch name only resolves via a branch rename redirect', async () => {
|
||||||
|
const {git: gitApi, repos: reposApi} = mockOctokit.rest
|
||||||
|
// The branches API follows rename redirects and returns the renamed branch
|
||||||
|
reposApi.getBranch.mockResolvedValue({data: {name: 'renamed-branch'}})
|
||||||
|
gitApi.getRef.mockRejectedValue(new Error('Not Found'))
|
||||||
|
gitApi.createRef.mockResolvedValue({})
|
||||||
|
|
||||||
|
const helper = new GitHubHelper('github.com', 'token')
|
||||||
|
const baseCommit = makeCommit([])
|
||||||
|
await helper.pushSignedCommits(
|
||||||
|
{} as GitCommandManager,
|
||||||
|
[],
|
||||||
|
baseCommit,
|
||||||
|
'/repo',
|
||||||
|
'owner/repo',
|
||||||
|
'branch'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(gitApi.getRef).toHaveBeenCalledWith({
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
ref: 'heads/branch'
|
||||||
|
})
|
||||||
|
expect(gitApi.createRef).toHaveBeenCalledWith({
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
sha: baseCommit.sha,
|
||||||
|
ref: 'refs/heads/branch'
|
||||||
|
})
|
||||||
|
expect(gitApi.updateRef).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('pushSignedCommits updates the ref when the branch exists', async () => {
|
||||||
|
const {git: gitApi} = mockOctokit.rest
|
||||||
|
gitApi.getRef.mockResolvedValue({data: {ref: 'refs/heads/branch'}})
|
||||||
|
gitApi.updateRef.mockResolvedValue({})
|
||||||
|
|
||||||
|
const helper = new GitHubHelper('github.com', 'token')
|
||||||
|
const baseCommit = makeCommit([])
|
||||||
|
await helper.pushSignedCommits(
|
||||||
|
{} as GitCommandManager,
|
||||||
|
[],
|
||||||
|
baseCommit,
|
||||||
|
'/repo',
|
||||||
|
'owner/repo',
|
||||||
|
'branch'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(gitApi.updateRef).toHaveBeenCalledWith({
|
||||||
|
owner: 'owner',
|
||||||
|
repo: 'repo',
|
||||||
|
sha: baseCommit.sha,
|
||||||
|
ref: 'heads/branch',
|
||||||
|
force: true
|
||||||
|
})
|
||||||
|
expect(gitApi.createRef).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Vendored
+4
-2
@@ -1644,8 +1644,10 @@ class GitHubHelper {
|
|||||||
createOrUpdateRef(branchRepository, branch, newHead) {
|
createOrUpdateRef(branchRepository, branch, newHead) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const repository = this.parseRepository(branchRepository);
|
const repository = this.parseRepository(branchRepository);
|
||||||
const branchExists = yield this.octokit.rest.repos
|
// Check the git ref directly rather than using the branches API, which
|
||||||
.getBranch(Object.assign(Object.assign({}, repository), { branch: branch }))
|
// follows branch rename redirects and can return a different branch.
|
||||||
|
const branchExists = yield this.octokit.rest.git
|
||||||
|
.getRef(Object.assign(Object.assign({}, repository), { ref: `heads/${branch}` }))
|
||||||
.then(() => true, () => false);
|
.then(() => true, () => false);
|
||||||
if (branchExists) {
|
if (branchExists) {
|
||||||
core.info(`Branch ${branch} exists; Updating ref`);
|
core.info(`Branch ${branch} exists; Updating ref`);
|
||||||
|
|||||||
@@ -438,10 +438,12 @@ export class GitHubHelper {
|
|||||||
newHead: string
|
newHead: string
|
||||||
) {
|
) {
|
||||||
const repository = this.parseRepository(branchRepository)
|
const repository = this.parseRepository(branchRepository)
|
||||||
const branchExists = await this.octokit.rest.repos
|
// Check the git ref directly rather than using the branches API, which
|
||||||
.getBranch({
|
// follows branch rename redirects and can return a different branch.
|
||||||
|
const branchExists = await this.octokit.rest.git
|
||||||
|
.getRef({
|
||||||
...repository,
|
...repository,
|
||||||
branch: branch
|
ref: `heads/${branch}`
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => true,
|
() => true,
|
||||||
|
|||||||
Reference in new issue
Block a user