Skip to content

Commit

Permalink
Prevent creating PR if one already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecRust committed Apr 16, 2024
1 parent 147caa6 commit 3d2a278
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jest.mock('../src/utils')
jest.mock('simple-git', () => {
const mockGit = {
addConfig: jest.fn(),
fetch: jest.fn(),
branch: jest.fn(),
checkoutLocalBranch: jest.fn(),
add: jest.fn(),
commit: jest.fn(),
Expand Down Expand Up @@ -48,6 +50,9 @@ describe('action', () => {
expect(core.getInput).toHaveBeenCalledWith('file-paths')
expect(getLatestWpVersion).toHaveBeenCalled()
expect(updateFiles).toHaveBeenCalled()

expect(mockGit.fetch).toHaveBeenCalled()
expect(mockGit.branch).toHaveBeenCalled()
expect(mockGit.checkoutLocalBranch).toHaveBeenCalled()
expect(mockGit.add).toHaveBeenCalledWith('.')
expect(mockGit.commit).toHaveBeenCalled()
Expand Down
7 changes: 7 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ export async function run(): Promise<void> {
const commitMessage = `Update WordPress 'Tested up to' version to ${wpVersion}`
await git.addConfig('user.email', authorEmail)
await git.addConfig('user.name', authorName)

if (createPR) {
await git.fetch(['--all'])
const branchName = `tested-up-to-${wpVersion.replace(/\./g, '-')}`
const branches = await git.branch()
if (branches?.all?.includes(`/${branchName}`)) {
console.log(`Branch '${branchName}' already exists.`)
core.setOutput('updated', 'false')
return
}

await git.checkoutLocalBranch(branchName)
await git.add('.')
await git.commit(commitMessage)
Expand Down

0 comments on commit 3d2a278

Please sign in to comment.