Skip to content

Add latest_pipeline endpoint (#656) - #737

Open
mvanhorn wants to merge 3 commits into
NARKOZ:masterfrom
mvanhorn:osc/656-latest-pipeline
Open

mvanhorn wants to merge 3 commits into
NARKOZ:masterfrom
mvanhorn:osc/656-latest-pipeline

Conversation

@mvanhorn

Copy link
Copy Markdown

Closes #656.

Wraps the GitLab REST endpoint `GET /projects/:id/pipelines/latest` (docs).

Usage

```ruby
Gitlab.latest_pipeline(5) # latest pipeline on the project's default branch
Gitlab.latest_pipeline(5, ref: 'develop') # latest pipeline on a specific ref
```

The method follows the same shape as the existing `pipeline` / `pipelines` methods in `lib/gitlab/client/pipelines.rb` and forwards `:ref` (and any other future query params) through `get`'s `query:` argument so callers don't have to remember which params the endpoint supports today.

Tests

`spec/gitlab/client/pipelines_spec.rb` adds two contexts:

  • "without a ref option" — verifies the request URL and that the response is parsed into a `Gitlab::ObjectifiedHash`.
  • "with a ref option" — verifies the `ref` query param is forwarded.

Backed by a new `spec/fixtures/latest_pipeline.json` fixture mirroring the existing `pipeline.json` shape.

I could not run `bundle exec rspec` locally — system Ruby is 2.6 and the gemspec requires Ruby 3.2. `ruby -c` confirms the source and spec parse cleanly. Happy to fix anything CI flags.

Wraps GET /projects/:id/pipelines/latest from the GitLab Pipelines
API. The new method takes an optional :ref to fetch the latest
pipeline for a specific branch or tag (defaults to the project's
default branch when omitted).

Adds an rspec spec covering both the no-ref and explicit-ref paths
and a latest_pipeline.json fixture that mirrors the existing
pipeline.json shape.
@github-actions

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Inactive label Jul 23, 2026
@mvanhorn

Copy link
Copy Markdown
Author

The Rubocop failure here isn't from this PR — I reproduced it on master at the same commit range and got the identical 6 offenses:

  • lib/gitlab/shell_history.rb:33 — Style/FileOpen
  • spec/gitlab/client/projects_spec.rb:549,566 and spec/gitlab/error_spec.rb:40,46,62 — RSpec/MatchWithSimpleRegex

This PR only touches lib/gitlab/client/pipelines.rb, its spec, and a fixture, none of which are flagged. 5 of 6 are autocorrectable with rubocop -a. Happy to send a separate lint-only PR for them if that's useful — kept out of this one so the endpoint change stays reviewable on its own.

@github-actions github-actions Bot removed the stale Inactive label Jul 26, 2026
@mvanhorn

Copy link
Copy Markdown
Author

The Rubocop job here isn't from this PR. I ran it locally on this branch and on master and got the same six offences either way:

  • lib/gitlab/shell_history.rb:33 -- Style/FileOpen
  • spec/gitlab/client/projects_spec.rb:549,566 and spec/gitlab/error_spec.rb:40,46,62 -- RSpec/MatchWithSimpleRegex

None of them are in the three files this PR touches (lib/gitlab/client/pipelines.rb, spec/gitlab/client/pipelines_spec.rb, spec/fixtures/latest_pipeline.json) -- it looks like a newer Rubocop picked up existing code. All four Ruby test jobs pass.

I've left them alone so this PR stays scoped to the endpoint. Happy to send a separate lint-only PR if that's useful -- five of the six are autocorrectable and the File.open one wants a real look.

@github-actions

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Inactive label Oct 26, 2026
Rubocop 1.92 flags Style/DirectiveScope, Style/FileOpen and
RSpec/MatchWithSimpleRegex in existing code, which fails the lint job.
Autocorrect the directive pairs and simple regex matches, and keep the
history file handle open with an inline disable since it is memoized.
@mvanhorn

mvanhorn commented Nov 1, 2026

Copy link
Copy Markdown
Author

Since the lint job was still red, I went ahead and pushed a small separate commit (7873194) that clears the Rubocop offenses so CI can go green. Rubocop 1.92 now reports 8, all in existing code:

  • Style/DirectiveScope in lib/gitlab.rb and lib/gitlab/api.rb: the disable/enable pairs become disable-next
  • RSpec/MatchWithSimpleRegex in projects_spec.rb and error_spec.rb: match(/x/) becomes include('x')
  • Style/FileOpen in shell_history.rb: inline disable, since the handle is memoized and meant to stay open

The endpoint change is untouched. If you'd rather keep the lint fixes out of this PR, I can drop the commit and send them separately.

json 3 raises on duplicate object keys and drops JSON.unparse, so a fresh
bundle fails nine examples. Three project access token fixtures listed
last_used_at twice, so keep the value the parser used, and call JSON.generate
in the request spec.
@github-actions github-actions Bot removed the stale Inactive label Nov 2, 2026

This branch has not been deployed

No deployments
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.

Latest pipeline API method

1 participant