# Build checks out wrong Pull Request: #79 instead of #7?

**URL:** <https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118>\
**Category:** Travis CI Discussions & Feedback\
**Tags:** github-integration, bug\
**Created:** [November 24, 2019, 10:50pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118 "2019-11-24T22:50:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeputons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yeputons/32/715_2.png) [@yeputons](https://travis-ci.community/u/yeputons)\
**Post date:** [November 24, 2019, 10:50pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/1 "2019-11-24T22:50:08Z")

</div>

Build: [https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/616376488?utm\_medium=notification&utm\_source=github\_status](https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/616376488?utm_medium=notification&utm_source=github_status)

On the top it says: “Pull Request #7” and “Commit 36384f8”. However, logs say:

```auto
$ git clone --depth=50 https://github.com/yeputons/hse-2019-pb-tasks.git yeputons/hse-2019-pb-tasks
$ cd yeputons/hse-2019-pb-tasks
$ git fetch origin +refs/pull/79/merge:

```

Note that it pulls Pull Request [#79](https://github.com/yeputons/hse-2019-pb-tasks/pull/79) instead of [#7](https://github.com/yeputons/hse-2019-pb-tasks/pull/7) for whatever reason. Consequently, it takes commit from the wrong pull request ([36384f8](https://github.com/yeputons/hse-2019-pb-tasks/commit/36384f8474ccad41957fc9f3993998098f95b08e) is a merge commit for [6ad824](https://github.com/yeputons/hse-2019-pb-tasks/commit/6ad824b999f6886d2a00c16f7518ec069d2c0c0f) for [#79](https://github.com/yeputons/hse-2019-pb-tasks/pull/79), no relation to #7 whatsoever).

This causes wrong status reporting for at least one PRs.

Any ideas on how to fix/work around this issue and make Travis report correct status? What can/should I fix to avoid such issue in the future?

**UPD** : I’ve tried closing and re-opening the PR to trigger a new job, it happened, but [same thing happens](https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/616413020): Travis pulls `refs/pull/79/merge` instead of `refs/pull/7/merge`.

This question was also posted at [StackOverflow](https://stackoverflow.com/questions/59023433/why-travis-ci-pulls-commits-from-wrong-pull-request-in-this-specific-job).

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [December 11, 2019, 6:18pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/2 "2019-12-11T18:18:35Z")

</div>

I looked at various data, and the only explanation I’ve come up with is that 79 was the reference we got when we configured the PR build. Unfortunately, GitHub makes available only 300 events for a repository, and the event we are interested in from 17 days ago is no longer available at this moment.

I’ve tested, and confirmed that closing and re-opening a PR sends new events, so in theory, we should be able to confirm the payload. To do this:

1. Close the PR in question if it’s not already.

2. Re-open the PR

3. Inspect the newly generated `PullRequestEvent` from [https://api.github.com/repos/yeputons/hse-2019-pb-tasks/events](https://api.github.com/repos/yeputons/hse-2019-pb-tasks/events). You can view it on Chrome, or run a simple query, if you know `jq`, for example:

---

<div class="post-metadata">

**Author:** ![yeputons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yeputons/32/715_2.png) [@yeputons](https://travis-ci.community/u/yeputons)\
**Post date:** [December 11, 2019, 6:54pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/3 "2019-12-11T18:54:11Z")

</div>

Thank you for reply!

I’ve tried closing and reopening a different PR with the same problem: [https://github.com/yeputons/hse-2019-pb-tasks/pull/11](https://github.com/yeputons/hse-2019-pb-tasks/pull/11)  
Corresponding build which was just triggered: [https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/623808071](https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/623808071)  
Logs still say `$ git fetch origin +refs/pull/119/merge:`

Corresponding GitHub payloads for closing and reopening the PR are available at [https://pastebin.com/wnBeXv3m](https://pastebin.com/wnBeXv3m) for your inspection. It does not have “119” as a substring, “11” only.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [December 11, 2019, 7:42pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/4 "2019-12-11T19:42:20Z")

</div>

Thanks for the extra effort here. Very much appreciated. It does appear that the payload from GitHub is correct.

> <https://gist.github.com/BanzaiMan/d70f16e10016c7de42750aab990873b4>

---

<div class="post-metadata">

**Author:** ![olgalupuleac](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/olgalupuleac/32/3506_2.png) [@olgalupuleac](https://travis-ci.community/u/olgalupuleac)\
**Post date:** [December 26, 2019, 6:44pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/5 "2019-12-26T18:44:52Z")

</div>

Here is an another example of this issue [https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/629655767](https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/629655767)  
The PR `#253` is checked instead of `#25`.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 10, 2020, 4:28pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/6 "2020-01-10T16:28:20Z")

</div>

Could someone push another commit to [https://github.com/yeputons/hse-2019-pb-tasks/pull/25](https://github.com/yeputons/hse-2019-pb-tasks/pull/25) and let me know as soon as possible so that I can examine the payload?

Thanks.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 10, 2020, 4:30pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/7 "2020-01-10T16:30:05Z")

</div>

Also, has anyone seen this issue other than this repository?

---

<div class="post-metadata">

**Author:** ![yeputons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yeputons/32/715_2.png) [@yeputons](https://travis-ci.community/u/yeputons)\
**Post date:** [January 10, 2020, 9:53pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/8 "2020-01-10T21:53:05Z")

</div>

Here you go: [https://github.com/yeputons/hse-2019-pb-tasks/pull/25/commits/c82c47ffd2aab6ea7e81f2d04e3d7885353fac5b](https://github.com/yeputons/hse-2019-pb-tasks/pull/25/commits/c82c47ffd2aab6ea7e81f2d04e3d7885353fac5b)

I have not used Travis CI extensively before, so I did not see this issue with other repositories.

---

<div class="post-metadata">

**Author:** ![yeputons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yeputons/32/715_2.png) [@yeputons](https://travis-ci.community/u/yeputons)\
**Post date:** [January 10, 2020, 9:56pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/9 "2020-01-10T21:56:45Z")

</div>

Payload displayed at [https://github.com/yeputons/hse-2019-pb-tasks/settings/hooks:](https://github.com/yeputons/hse-2019-pb-tasks/settings/hooks:) [https://gist.github.com/yeputons/c275bc261e74048eb280c8c8ee98812a](https://gist.github.com/yeputons/c275bc261e74048eb280c8c8ee98812a)

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 11, 2020, 2:40am UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/10 "2020-01-11T02:40:56Z")

</div>

Hmm. I don’t see these events for some reason:

```auto
$ curl -sSfL https://api.github.com/repos/yeputons/hse-2019-pb-tasks/events | jq 'map(.created_at)'
[
  "2020-01-03T09:30:32Z",
  "2020-01-03T09:29:49Z",
  "2019-12-31T22:09:27Z",
  "2019-12-30T04:22:03Z",
  "2019-12-30T04:11:01Z",
  "2019-12-30T04:08:10Z",
  "2019-12-29T23:25:36Z",
  "2019-12-29T23:25:33Z",
  "2019-12-29T20:34:42Z",
  "2019-12-29T20:00:15Z",
  "2019-12-29T20:26:27Z",
  "2019-12-29T20:26:02Z",
  "2019-12-29T20:19:13Z",
  "2019-12-29T19:58:47Z",
  "2019-12-29T19:56:17Z",
  "2019-12-29T19:57:44Z",
  "2019-12-29T19:58:34Z",
  "2019-12-29T19:50:40Z",
  "2019-12-29T19:49:48Z",
  "2019-12-29T19:48:15Z",
  "2019-12-13T14:47:34Z",
  "2019-12-13T14:49:30Z",
  "2019-12-29T19:40:58Z",
  "2019-12-29T19:39:16Z",
  "2019-12-29T19:37:42Z",
  "2019-12-29T19:28:39Z",
  "2019-12-29T19:30:52Z",
  "2019-12-29T19:29:29Z",
  "2019-12-28T09:38:33Z",
  "2019-12-23T23:31:09Z"
]

```

Since I can’t see the payload, could you paste it here?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [January 11, 2020, 2:42am UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/11 "2020-01-11T02:42:02Z")

</div>

I will note that [https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/635477758#L127](https://travis-ci.org/yeputons/hse-2019-pb-tasks/builds/635477758#L127) checks out the correct merge commit.

---

<div class="post-metadata">

**Author:** ![yeputons](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yeputons/32/715_2.png) [@yeputons](https://travis-ci.community/u/yeputons)\
**Post date:** [January 11, 2020, 8:37am UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/12 "2020-01-11T08:37:55Z")

</div>

Sure, the webhook payload is available at [https://gist.github.com/yeputons/c275bc261e74048eb280c8c8ee98812a](https://gist.github.com/yeputons/c275bc261e74048eb280c8c8ee98812a) .

I suspect that pushing another commit “fixes” the issue, while closing and reopening does not, as it happened above with PR 11.

---

<div class="post-metadata">

**Author:** ![KrisThielemans](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/kristhielemans/32/4192_2.png) [@KrisThielemans](https://travis-ci.community/u/KrisThielemans)\
**Post date:** [March 2, 2020, 5:45pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/13 "2020-03-02T17:45:51Z")

</div>

I pushed some commits to a PR [https://github.com/UCL/STIR/pull/44](https://github.com/UCL/STIR/pull/44). However, the Travis jobs actually ran a commit from PR 449 [https://github.com/UCL/STIR/pull/449](https://github.com/UCL/STIR/pull/449) (which was then still open).

Here’s a link to one of the jobs [https://travis-ci.org/UCL/STIR/jobs/657085845?utm\_medium=notification&utm\_source=github\_status](https://travis-ci.org/UCL/STIR/jobs/657085845?utm_medium=notification&utm_source=github_status)

Checking the log file for that job [https://travis-ci.org/UCL/STIR/jobs/657290596#L1071](https://travis-ci.org/UCL/STIR/jobs/657290596#L1071) says

- branch refs/pull/449/merge -\> FETCH\_HEAD

which clearly should have been:

- branch refs/pull/44/merge -\> FETCH\_HEAD

This looks like a Travis bug?

---

<div class="post-metadata">

**Author:** ![casperdcl](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/casperdcl/32/3945_2.png) [@casperdcl](https://travis-ci.community/u/casperdcl)\
**Post date:** [March 2, 2020, 6:40pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/14 "2020-03-02T18:40:03Z")

</div>

Looks like Travis is picking up the latest wildcard-matched `refs/pull/${TRAVIS_PULL_REQUEST}*` rather than `refs/pull/${TRAVIS_PULL_REQUEST}/merge`

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [March 6, 2020, 7:24pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/15 "2020-03-06T19:24:54Z")

</div>

> [@KrisThielemans](#):
>
> This looks like a Travis bug?

It seems that way. The trouble is that, although we’ve had reports, we have been unable to reproduce it.

What happens if you push a new commit to this PR?

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [March 16, 2020, 8:59pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/16 "2020-03-16T20:59:56Z")

</div>

All right. I have a reproduction.

[https://travis-ci.org/github/BanzaiMan/travis\_production\_test/builds/663233650#L187](https://travis-ci.org/github/BanzaiMan/travis_production_test/builds/663233650#L187)  
[https://travis-ci.org/github/BanzaiMan/travis\_production\_test/builds/663237225#L179](https://travis-ci.org/github/BanzaiMan/travis_production_test/builds/663237225#L179)

We’ll look into it.

---

<div class="post-metadata">

**Author:** ![BanzaiMan](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/banzaiman/32/67_2.png) [@BanzaiMan](https://travis-ci.community/u/BanzaiMan)\
**Post date:** [March 19, 2020, 6:20pm UTC](https://travis-ci.community/t/build-checks-out-wrong-pull-request-79-instead-of-7/6118/17 "2020-03-19T18:20:46Z")

</div>

We’ve deployed a fix to this issue. To summarize:

## Problem

When there are multiple _open_ PRs for a repository where one matches the prefix of another (e.g., `7` & `79`, `44` & `443`), if a new PR build is triggered on the shorter/older PR, the merge commit from the newest one is checked out instead.

## Solution

We’ve fixed the bug. If you saw the problem earlier, please push a new commit to the old PR. This should result in checking out the correct merge commit.

### See

[https://travis-ci.org/github/BanzaiMan/travis\_production\_test/builds/664525177#L170](https://travis-ci.org/github/BanzaiMan/travis_production_test/builds/664525177#L170) (PR 7, while PR 76 was still open.)
