Commit Graph

270 Commits

Author SHA1 Message Date
Shinya Maeda d4b4693663 Abstract auto merge processes
We have one auto merge strategy today - Merge When Pipeline
Succeeds.

In order to add more strategies for Merge Train feature,
we abstract the architecture to be more extensible.

Removed arguments

Fix spec
2019-06-03 13:15:29 +07:00
Oswaldo Ferreira 4246a62118 Add payload to the service response
This introduces payload to the ServiceResponse with
the merge ref HEAD commit data
2019-05-31 19:16:01 -03:00
Oswaldo Ferreira 96db70a444 Simplify merge_ref_head methods 2019-05-31 19:16:01 -03:00
Oswaldo Ferreira b965009ddd Automatically update MR merge-ref along merge status
This couples the code that transitions the `MergeRequest#merge_status`
and refs/merge-requests/:iid/merge ref update.

In general, instead of directly telling `MergeToRefService` to update
the merge ref, we should rely on `MergeabilityCheckService` to keep
both the merge status and merge ref synced. Now, if the merge_status is
`can_be_merged` it means the merge-ref is also updated to the latest.

We've also updated the logic to be more systematic and less user-based.
2019-05-31 19:16:01 -03:00
Kerri Miller c04ea58350 Revert "Merge branch '55127-add-delay-after-mr-creation-for-async-tasks-to-complete' into 'master'"
This reverts merge request !27978
2019-05-20 17:37:43 +00:00
Kerri Miller 29f9d92642 Confirm existence of head_pipeline if pipeline success required
Pipelines are created by an async worker, so a rapid sequence of API
calls can trigger a state where the pipeline, whose existence is part of
determining if we wait for the pipeline to successfully complete before
merging, can trigger the MR to be immediately merged instead.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/55127
2019-05-07 16:06:53 +00:00
Stan Hu d3fa9c9539 Fix remove_source_branch merge request API handling
Users attempting to set merge requests to `remove_source_branch` to
`false` would encounter an Error 500 because the UpdateService and API
checked `present?`, which would always return `false`. We now just
use `has_key?` to decide whether the parameter is present.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/60530
2019-04-15 11:27:33 -07:00
Oswaldo Ferreira ca884980ee [CE] Support multiple assignees for merge requests
Backports https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/10161
(code out of ee/ folder).
2019-04-08 18:40:00 -03:00
Paul Slaughter 59ac0924da Fix IDE detecting MR from fork branch
**Why?**
Currently the IDE loads a merge request based on only the
`source_branch` name. This means it loads MR's from
forks that have the same branch name (not good).

- This required updating the BE API to accept `source_project_id`
2019-04-05 07:29:53 +00:00
Igor 9745d0de2f Provide EE backports for filtering by approver feature
Adds custom validator for ArrayNoneAny param
Extracts some logic in js into separate files
2019-03-07 23:55:45 +00:00
Igor e779477e8c Revert "Merge branch 'id-1951-filter-merge-requests-by-approvers' into 'master'"
This reverts merge request !24982
2019-03-07 14:59:43 +00:00
Sean McGivern 3781cbe0c3 Merge branch 'sh-optimize-todos-api' into 'master'
Significantly reduce N+1 queries in /api/v4/todos endpoint

Closes #40378

See merge request gitlab-org/gitlab-ce!25711
2019-03-07 10:29:04 +00:00
Igor 572e3f2254 Provide EE backports for filtering by approver feature
Adds custom validator for ArrayNoneAny param
Extracts some logic in js into separate files
2019-03-07 07:06:54 +00:00
Stan Hu 062efe4f7a Significantly reduce N+1 queries in /api/v4/todos endpoint
By preloading associations and batching issuable metadata lookups,
we can significantly cut the number of SQL queries needed to load
the Todos API endpoint.

On GitLab.com, my own tests showed my user's SQL queries went
from 365 to under 60 SQL queries.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/40378
2019-03-06 07:03:46 -08:00
Alexandru Croitor be3578d245 Add array support for labels
* Support label parameter as comma separated and array of strings
for merge requests and issues api endpoints
2019-03-06 13:28:42 +02:00
Mario de la Ossa ee8cb2d1b3 PUT MergeRequest API endpoint - accept labels as an array 2019-03-06 12:56:29 +02:00
Oswaldo Ferreira e8fbc070e0 Add API support for refreshing merge ref path
Add a merge_requests/:iid/merge_to_ref API which make
use of the groundwork to write merge results into
refs/merge-requests/:iid/merge.
2019-02-26 12:37:32 -03:00
Nick Thomas c85a768ca5
Respect the should_remove_source_branch parameter to the merge API 2019-02-25 14:09:48 +00:00
Nermin Vehabovic ff671366cb Added: Include order by ID desc for tie breakers in pagination 2019-02-16 11:03:42 +01:00
Luke Duncalfe b37266004c API support for squash commit message during merge
Issues
https://gitlab.com/gitlab-org/gitlab-ce/issues/47149
https://gitlab.com/gitlab-org/gitlab-ce/issues/56014
2019-02-07 10:05:54 +13:00
Sean McGivern 068b41275f Merge branch 'search-title' into 'master'
Add 'in' filter that modifies scope of 'search' filter  to issues and merge requests API

See merge request gitlab-org/gitlab-ce!24350
2019-02-05 09:52:40 +00:00
Hiroyuki Sato 40198f8184 Fix grammar and spelling 2019-02-05 17:32:27 +09:00
Sam Bigelow c607b35824 Use 'delete' instead of 'remove' for source branch
This is to match `git branch -D <branchname>`
2019-01-22 12:57:01 -05:00
Hiroyuki Sato d32aec06fe Add 'in' filter that modifies scope of 'search' filter to issues and merge requests API 2019-01-14 12:02:55 +09:00
Nick Thomas 93d6f56968 Merge branch 'if-52811-fix_namespaces_api_routing' into 'master'
Fix API::Namespaces routing to accept namepaces with dots

See merge request gitlab-org/gitlab-ce!22912
2018-11-30 15:08:56 +00:00
Nick Thomas 04ceb69f3e
Allow the status of a rebase to be determined 2018-11-28 12:57:47 +00:00
Imre Farkas b1e070bf49
Fix API::Namespaces to accept namepaces with dots
It also renames the API::PROJECT_ENDPOINT_REQUIREMENTS constant to
API::NAMESPACE_OR_PROJECT_REQUIREMENTS
2018-11-28 12:54:11 +01:00
Nick Thomas 9f28729827
Add a rebase API endpoint for merge requests 2018-11-27 18:04:33 +00:00
Douwe Maan 34e8d9726d
Expose {closed,merged}_{at,by} in merge requests API index 2018-11-05 13:49:10 +01:00
Heinrich Lee Yu bf1ed85a9d Refactor api validator to separate class 2018-10-26 10:32:14 +08:00
Heinrich Lee Yu 006631f882 Apply similar change to MRs API 2018-10-26 10:32:14 +08:00
Chantal Rollison 38f3d59fd0 #13650 added wip search functionality and tests 2018-10-03 08:15:00 +00:00
gfyoung 3836d69119 Enable frozen string in lib/api and lib/backup
Partially addresses #47424.

Had to make changes to spec files because
stubbing methods on frozen objects is a mess
in RSpec and leads to failures:

https://github.com/rspec/rspec-mocks/issues/1190
2018-09-29 21:04:50 -07:00
Yorick Peterse 2039c8280d
Disable existing offenses for the CodeReuse cops
This whitelists all existing offenses for the various CodeReuse cops, of
which most are triggered by the CodeReuse/ActiveRecord cop.
2018-09-11 17:32:00 +02:00
🙈 jacopo beschi 🙉 20bd1e6b34 Resolve "Return how many commits the source branch is behind the target branch through the API" 2018-09-05 13:07:02 +00:00
Felipe Artur fdb5f285f9 Retrieve merge request closing issues from database cache 2018-08-06 11:58:22 -03:00
Phil Hughes e241fe6b78
added API docs
CHANGELOG
improved comments in API code
improved spec description
2018-07-05 15:44:56 +01:00
Phil Hughes 5428e91374
only include _html fields when asked for 2018-07-05 15:44:54 +01:00
Chantal Rollison c2b622b2a4 Add locked state to merge request API 2018-06-28 07:12:00 -07:00
Robert Speicher 6ced2f1243 Merge branch '42751-rename-mr-maintainer-push' into 'master'
Rephrase Merge Request Maintainer Edit

See merge request gitlab-org/gitlab-ce!19061
2018-06-05 15:04:18 +00:00
Stan Hu bd4bfcc641 Fix N+1 with source projects in merge requests API
Now that we are checking `MergeRequest#for_fork?`, we also need
the source project preloaded for a merge request.
2018-06-03 04:24:23 -07:00
Mark Chao 0d44f4d50e Rephrase "maintainer" to more precise "members who can merge to the target branch"
"Maintainer" will be freed to be used for #42751
2018-06-01 14:33:12 +09:00
Felipe Artur 8ed12efecd Add merge requests list endpoint for groups 2018-05-31 15:29:07 +00:00
blackst0ne 4cff66a6c4 Add 'squash and rebase' feature to CE 2018-05-29 20:51:43 +11:00
Mark Chao d839b880a2 Add created_by_me and assigned_to_me scopes
Deprecate corresponding dash versions created-by-me and assigned-to-me
2018-05-21 09:55:30 +08:00
Bob Van Landuyt 71ccfde322 Correct permissions for creating merge requests from issues
This could only be possible for users that can create merge requests
within a project.

So they need to be a allowed to create a branch and create a merge request.
2018-04-11 10:51:17 +02:00
Bob Van Landuyt 9b27027619 Add documentation for allowing maintainers to push 2018-03-07 16:59:17 +01:00
Bob Van Landuyt 8b2ec23fef Set `allow_maintainer_to_push` using the API 2018-03-07 16:59:17 +01:00
Lin Jen-Shin 156cc98d10 Unify lib/api/merge_requests.rb with EE 2018-03-06 01:44:51 +08:00
Sean McGivern 5a1da682a7 Merge branch '41616-api-issues-between-date' into 'master'
Resolve "API support for selecting only  updated issues before/after a given date"

Closes #41616

See merge request gitlab-org/gitlab-ce!17417
2018-03-05 14:04:35 +00:00
Jacopo 168ff28506 Adds updated_at filter to issues and merge_requests API 2018-03-05 14:10:32 +01:00
haseeb bb89412ffb expose metrics in merge request api 2018-03-02 16:48:55 +00:00
Sean McGivern 2f7dffe548 Add source and target branch filters to merge requests API 2018-03-01 10:41:02 +00:00
Yorick Peterse cca61980d5
Track and act upon the number of executed queries
This ensures that we have more visibility in the number of SQL queries
that are executed in web requests. The current threshold is hardcoded to
100 as we will rarely (maybe once or twice) change it.

In production and development we use Sentry if enabled, in the test
environment we raise an error. This feature is also only enabled in
production/staging when running on GitLab.com as it's not very useful to
other users.
2018-02-01 17:00:46 +01:00
Sean McGivern 06713cb7b0 Merge branch '39214__pipeline_api' into 'master'
Add `pipelines` endpoint to merge requests API

Closes #39214

See merge request gitlab-org/gitlab-ce!15454
2018-01-11 11:29:53 +00:00
Tony Rom 7ed08fcd5d Fix style 2018-01-10 20:05:34 +03:00
Brent Greeff 34b9cc9674 API: get participants from merge_requests & issues 2018-01-05 15:21:53 +00:00
Mark Fletcher 055543b915 Add optional `search` param for Merge Requests API 2017-12-20 07:23:57 +00:00
Mark Fletcher c9732b3c6d Employ declared_params in finder methods for MR and Issue API lists
- Ensure that unwanted params are no passed to actual finder classes
2017-12-20 07:23:57 +00:00
Tony Rom fd88b0ca56 Add `pipelines` endpoint to merge requests API 2017-12-15 19:53:57 +03:00
George Andrinopoulos 7fb1bb01bd Create issue and merge request destroy services 2017-11-25 22:09:18 +02:00
Sean McGivern 991bf24ec8 Use latest_merge_request_diff association
Compared to the merge_request_diff association:

1. It's simpler to query. The query uses a foreign key to the
   merge_request_diffs table, so no ordering is necessary.
2. It's faster for preloading. The merge_request_diff association has to load
   every diff for the MRs in the set, then discard all but the most recent for
   each. This association means that Rails can just query for N diffs from N
   MRs.
3. It's more complicated to update. This is a bidirectional foreign key, so we
   need to update two tables when adding a diff record. This also means we need
   to handle this as a special case when importing a GitLab project.

There is some juggling with this association in the merge request model:

* `MergeRequest#latest_merge_request_diff` is _always_ the latest diff.
* `MergeRequest#merge_request_diff` reuses
  `MergeRequest#latest_merge_request_diff` unless:
    * Arguments are passed. These are typically to force-reload the association.
    * It doesn't exist. That means we might be trying to implicitly create a
      diff. This only seems to happen in specs.
    * The association is already loaded. This is important for the reasons
      explained in the comment, which I'll reiterate here: if we a) load a
      non-latest diff, then b) get its `merge_request`, then c) get that MR's
      `merge_request_diff`, we should get the diff we loaded in c), even though
      that's not the latest diff.

Basically, `MergeRequest#merge_request_diff` is the latest diff in most cases,
but not quite all.
2017-11-23 12:14:56 +00:00
Mark Fletcher ff1e3a47c4 Fix namespacing for MergeWhenPipelineSucceedsService in MR API 2017-10-30 17:19:51 +00:00
Sean McGivern a68a39e341 Merge branch '18608-lock-issues-v2' into 'master'
Resolve "Lock issue and merge request"

Closes #18608

See merge request gitlab-org/gitlab-ce!14531
2017-10-06 16:47:27 +00:00
Vitaliy @blackst0ne Klachkov c55a9ac4ae Remove 'Repo' prefix from API entites 2017-10-05 19:48:05 +11:00
Luke "Jared" Bennett ff7b545c8e
Merge remote-tracking branch 'origin/master' into 18608-lock-issues 2017-09-20 15:23:00 +01:00
haseeb ff4e81e0ae fix #35290 Make read-only API for public merge requests available without authentication 2017-09-18 17:29:17 +00:00
Jarka Kadlecova 073ba05d31 Support discussion lock in the API 2017-09-14 14:50:32 +02:00
Hiroyuki Sato 7e42711659 Add my_reaction_emoji param to /merge_requests API 2017-09-05 11:56:17 +09:00
Robert Schilling 6a2ee0968e API: Use defined project requirements 2017-08-31 14:57:47 +02:00
Robert Speicher 966b635221 Merge branch '28453-add-time-estimate-time-spent-to-api-issue-output' into 'master'
Add time stats to Issue and Merge Request API

Closes #28453

See merge request !13335
2017-08-30 17:35:14 +00:00
Travis Miller 749c389345 Add time stats to issue and merge request API end points 2017-08-29 08:31:36 -05:00
Robert Schilling e80313f9ee Conditionally destroy a ressource 2017-08-28 16:40:25 +02:00
Robert Schilling 998afa5f74 API: Respect the 'If-Unmodified-Since' for delete endpoints 2017-08-28 16:40:25 +02:00
Toon Claes d77088bb0b Default /merge_request API endpoint to `scope=created-by-me`
This matches the behavior of the /issues endpoint.
2017-07-28 00:07:28 +02:00
Toon Claes d7505de8b3 Add top-level /merge_requests API endpoint
And add support for additional query parameters:
- `author_id`: Returns merge requests created by the given user `id`
- `assignee_id`: Returns merge requests assigned to the given user `id`
- `scope`: Return merge requests for the given scope: `created-by-me`, `assigned-to-me` or `all`
2017-07-27 23:34:57 +02:00
Jarka Kadlecova 7bee7b848a Support both internal and external issue trackers 2017-07-24 08:13:43 +02:00
Dmitriy Zaporozhets 6b8ad689da
Update grape gem
New version of the gem returns 200 status code on delete with content
instead of 204 so we explicitly set status code to keep existing
behavior

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
2017-07-20 16:33:18 +03:00
Stan Hu faf9543827 Use view=simple for simplifying merge requests API 2017-07-11 08:02:13 -07:00
Stan Hu e17ac5705d Add a simple mode to merge request API
The current "basic" merge request API still loads too much data. For integrations
like the Trello Power-up, we just need the basics.

Closes #34920
2017-07-11 06:32:13 -07:00
Stan Hu 1f0ee9ca19 Fix sort ordering with merge request API 2017-07-10 15:08:07 -07:00
Stan Hu ef526ff33c Paginate the merge requests API earlier to avoid eager loading every merge request
Fixes a performance regression introduced in !12732
2017-07-10 13:56:46 -07:00
Stan Hu 88c4248ac7 Remove remaining N+1 queries in merge requests API with emojis and labels
Closes #34159
2017-07-08 22:19:34 -07:00
Stan Hu b963d45ca4 Remove many N+1 queries with merge requests API
Identified via `ENABLE_BULLET=1 bundle exec rspec spec/requests/api/merge_requests_spec.rb:34`

Improves speed of #34159
2017-07-07 16:31:21 -07:00
Rémy Coutable 9fe6c2b2c2 Merge branch 'add-since-and-until-params-to-issuables' into 'master'
add created_after and created_before params to issuables

Closes #32901

See merge request !12151
2017-06-19 12:13:27 +00:00
Kyle Bishop ef633d2478 add since and until params to issuables 2017-06-18 15:43:51 -07:00
Felipe Artur c472017078 Fix API bug accepting wrong merge requests parameters 2017-06-16 16:33:09 -03:00
mhasbini ccac05dd90 Fix 404 when upstream has disabled merge requests 2017-04-27 01:04:07 +03:00
Robert Schilling 2ea5d4b7af Ability to filter merge requests by labels and milestones 2017-04-25 22:07:38 +02:00
Chris Wilson e670cb271e Fix updating merge_when_build_succeeds via merge API endpoint
When updating a merge request via the `/merge` endpoint we
check the `mergeable` and `mergeable_state` status, these will return
`false` if the application option only_allow_merge_if_pipeline_succeeds is
enabled. We should skip CI checks if the request uses the
merge_when_pipeline_succeeds param

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/22740
2017-04-24 20:51:05 +10:00
Oswaldo Ferreira fd32960e7c Separate CE params on Grape API 2017-04-10 16:13:48 -03:00
Toon Claes d536d9590b Remove `:id/merge_requests/:merge_request_iid/comments` endpoints
Comments for a merge request should be obtained to the `notes` endpoint.
2017-03-27 10:23:14 +02:00
Rémy Coutable 63360adeae
Add `requirements: { id: %r{[^/]+} }` for all projects and groups namespaced API routes
Signed-off-by: Rémy Coutable <remy@rymai.me>
2017-03-16 18:00:24 +01:00
Timothy Andrew 719327112c
API routes referencing a specific merge request should use the MR `iid`
- As opposed to the `id` that was previously being used.
- This brings the API routes closer to the web interface's routes.
- This is specific to API v4.
2017-03-07 13:06:42 +05:30
Adam Niedzielski c727d4328f Remove "subscribed" field from API responses returning list of issues or merge requests 2017-03-06 14:17:07 +01:00
James Lopez a0101ebf84 Update occurrences of MWBS to MWPS
Rename column in the database
 Rename fields related to import/export feature
 Rename API endpoints
 Rename documentation links
 Rename the rest of occurrences in the code
 Replace the images that contain the words "build succeeds" and docs referencing to them
 Make sure pipeline is green and nothing is missing.

updated doc images

renamed only_allow_merge_if_build_succeeds in projects and fixed references

more updates

fix some spec failures

fix rubocop offences

fix v3 api spec

fix MR  specs

fixed issues with partials

fix MR spec

fix alignment

add missing v3 to v4 doc

wip - refactor v3 endpoints

fix specs

fix a few typos

fix project specs

copy entities fully to V3

fix  entity error

more fixes

fix failing specs

fixed missing entities in V3 API

remove comment

updated code based on feedback

typo

fix spec
2017-03-01 12:02:02 +01:00
Robert Schilling 01ea65e0e9 Paginate all endpoints that return an array 2017-02-16 15:32:01 +01:00
James Edwards-Jones 744df2dca8 Update MergeRequest API state_event option documentation 2017-02-09 14:23:49 +00:00
Oswaldo Ferreira c2d64d6702 Remove deprecated MR and Issue endpoints and preserve V3 namespace 2017-02-06 10:12:20 -02:00
Robert Speicher 3a5df1d8fc Merge branch 'fix-api-mr-permissions' into 'security'
Ensure that only privileged users can access merge requests in the API

See merge request !2053
2017-01-23 13:54:35 -05:00