Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #198: Avoid getting alerts from Code scanning #201

Conversation

ivanramosnet
Copy link
Contributor

Fix issue #198

await expect(gitRepo.hasCommits()).resolves.toBe(true)
})

it('should fail when the repo has not been initialized and check if it has commits', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @ivanramosnet I did not understand the test intention well. Maybe it's only me but I would rephrase it to:

it should fail while checking if the repo has commits when it has not been initialized

@josecelano
Copy link
Member

hi @ivanramosnet can you rebase? There is a failing test because now we need the job id in the commit subject. You only need to add it to this function:

export function dummyCommitSubjectText(): string {
  return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

@@ -37,4 +44,33 @@ describe('GitRepo', () => {

expect(gitRepo.isInitialized()).toBe(true)
})

it('should check if a repo has commits', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe:
initialize new git repository, check that there are no comments, add a test comment, check for the comment

@josecelano
Copy link
Member

josecelano commented May 17, 2022

hi, @ivanramosnet I think tests are failing. Tests are not being executed on PR from forks. After you rebase make sure tests pass: yarn test

UPDATE:

Tests only fail if you execute them locally with yarn test without having any committer configuration in your Git configuration. If you remove these lines from your global git config:

[user]
        name = Your Name
        email = Your Email
        signingkey = XXXX

You will see these errors:

Summary of all failing tests
 FAIL  __tests__/e2e/main.test.ts (11.704 s)
  ● GitHub Action › should create a new job

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      124 |     const output = executeAction(env)
      125 |
    > 126 |     expect(getOutputVariable('job_created', output.toString())).toBe('true')
          |                                                                 ^
      127 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      128 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      129 |     )

      at __tests__/e2e/main.test.ts:126:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should get the next job

    expect(received).toBe(expected) // Object.is equality

    Expected: "test"
    Received: undefined

      145 |     const output = executeAction(env)
      146 |
    > 147 |     expect(getOutputVariable('job_payload', output.toString())).toBe(
          |                                                                 ^
      148 |       dummyPayload()
      149 |     )
      150 |     expect(getOutputVariable('job_commit', output.toString())).toBe(

      at __tests__/e2e/main.test.ts:147:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should mark the pending job as started

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      169 |     const output = executeAction(env)
      170 |
    > 171 |     expect(getOutputVariable('job_started', output.toString())).toBe('true')
          |                                                                 ^
      172 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      173 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      174 |     )

      at __tests__/e2e/main.test.ts:171:65
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should mark the pending job as finished

    expect(received).toBe(expected) // Object.is equality

    Expected: "true"
    Received: undefined

      198 |     })
      199 |
    > 200 |     expect(getOutputVariable('job_finished', output.toString())).toBe('true')
          |                                                                  ^
      201 |     expect(getOutputVariable('job_commit', output.toString())).toBe(
      202 |       getLatestCommitHash(gitRepo.getDir()).getHash()
      203 |     )

      at __tests__/e2e/main.test.ts:200:66
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should allow to overwrite commit signing key

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:224:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should allow to disable commit signing for a given commit

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:243:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)

  ● GitHub Action › should always overwrite the commit author with: NautilusCyberneering[bot] <bot@nautilus-cyberneering.de>

    Command failed: git log --show-signature -n1
    fatal: your current branch 'main' does not have any commits yet

      88 | export function gitLogForLatestCommit(gitRepoDir: string): string {
      89 |   const output = cp
    > 90 |     .execFileSync('git', ['log', '--show-signature', '-n1'], {
         |      ^
      91 |       cwd: gitRepoDir
      92 |     })
      93 |     .toString()

      at gitLogForLatestCommit (src/__tests__/helpers.ts:90:6)
      at __tests__/e2e/main.test.ts:259:47
      at fulfilled (__tests__/e2e/main.test.ts:28:58)


Test Suites: 1 failed, 20 passed, 21 total
Tests:       7 failed, 117 passed, 124 total

I think this is related to #175. Tests should set up the configuration they need and not rely on preexisting configurations.

@josecelano
Copy link
Member

Replaced by #235

@josecelano
Copy link
Member

Merged with #235

@josecelano josecelano closed this Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix code scanning alert - Shell command built from environment values
3 participants