<!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>class MergeRequest - Rails Application Documentation</title> <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet"> <script type="text/javascript"> var rdoc_rel_prefix = "./"; </script> <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script> <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script> <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script> <script type="text/javascript" charset="utf-8" src="./js/search.js"></script> <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script> <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script> <body id="top" class="class"> <nav id="metadata"> <nav id="home-section" class="section"> <h3 class="section-header"> <a href="./index.html">Home</a> <a href="./table_of_contents.html#classes">Classes</a> <a href="./table_of_contents.html#methods">Methods</a> </h3> </nav> <nav id="search-section" class="section project-section" class="initially-hidden"> <form action="#" method="get" accept-charset="utf-8"> <h3 class="section-header"> <input type="text" name="search" placeholder="Search" id="search-field" title="Type to search, Up and Down to navigate, Enter to load"> </h3> </form> <ul id="search-results" class="initially-hidden"></ul> </nav> <div id="file-metadata"> <nav id="file-list-section" class="section"> <h3 class="section-header">Defined In</h3> <ul> <li>app/models/merge_request.rb </ul> </nav> </div> <div id="class-metadata"> <nav id="parent-class-section" class="section"> <h3 class="section-header">Parent</h3> <p class="link">ActiveRecord::Base </nav> <!-- Included Modules --> <nav id="includes-section" class="section"> <h3 class="section-header">Included Modules</h3> <ul class="link-list"> <li><a class="include" href="IssueCommonality.html">IssueCommonality</a> <li><a class="include" href="Votes.html">Votes</a> </ul> </nav> <!-- Method Quickref --> <nav id="method-list-section" class="section"> <h3 class="section-header">Methods</h3> <ul class="link-list"> <li><a href="#method-c-find_all_by_branch">::find_all_by_branch</a> <li><a href="#method-i-automerge-21">#automerge!</a> <li><a href="#method-i-broken_diffs-3F">#broken_diffs?</a> <li><a href="#method-i-can_be_merged-3F">#can_be_merged?</a> <li><a href="#method-i-check_if_can_be_merged">#check_if_can_be_merged</a> <li><a href="#method-i-closed_event">#closed_event</a> <li><a href="#method-i-commits">#commits</a> <li><a href="#method-i-diffs">#diffs</a> <li><a href="#method-i-human_state">#human_state</a> <li><a href="#method-i-last_commit">#last_commit</a> <li><a href="#method-i-mark_as_merged-21">#mark_as_merged!</a> <li><a href="#method-i-mark_as_unchecked">#mark_as_unchecked</a> <li><a href="#method-i-mark_as_unmergable">#mark_as_unmergable</a> <li><a href="#method-i-merge-21">#merge!</a> <li><a href="#method-i-merge_event">#merge_event</a> <li><a href="#method-i-merged-3F">#merged?</a> <li><a href="#method-i-mr_and_commit_notes">#mr_and_commit_notes</a> <li><a href="#method-i-open-3F">#open?</a> <li><a href="#method-i-probably_merged-3F">#probably_merged?</a> <li><a href="#method-i-reload_code">#reload_code</a> <li><a href="#method-i-reloaded_commits">#reloaded_commits</a> <li><a href="#method-i-reloaded_diffs">#reloaded_diffs</a> <li><a href="#method-i-to_raw">#to_raw</a> <li><a href="#method-i-unchecked-3F">#unchecked?</a> <li><a href="#method-i-unmerged_commits">#unmerged_commits</a> <li><a href="#method-i-unmerged_diffs">#unmerged_diffs</a> <li><a href="#method-i-valid_diffs-3F">#valid_diffs?</a> <li><a href="#method-i-validate_branches">#validate_branches</a> </ul> </nav> </div> <div id="project-metadata"> <nav id="fileindex-section" class="section project-section"> <h3 class="section-header">Pages</h3> <ul> <li class="file"><a href="./doc/README_FOR_APP.html">README_FOR_APP</a> </ul> </nav> <nav id="classindex-section" class="section project-section"> <h3 class="section-header">Class and Module Index</h3> <ul class="link-list"> <li><a href="./Gitlab.html">Gitlab</a> <li><a href="./Gitlab/API.html">Gitlab::API</a> <li><a href="./Gitlab/APIHelpers.html">Gitlab::APIHelpers</a> <li><a href="./Gitlab/AppLogger.html">Gitlab::AppLogger</a> <li><a href="./Gitlab/Auth.html">Gitlab::Auth</a> <li><a href="./Gitlab/Encode.html">Gitlab::Encode</a> <li><a href="./Gitlab/Entities.html">Gitlab::Entities</a> <li><a href="./Gitlab/Entities/Hook.html">Gitlab::Entities::Hook</a> <li><a href="./Gitlab/Entities/Issue.html">Gitlab::Entities::Issue</a> <li><a href="./Gitlab/Entities/Milestone.html">Gitlab::Entities::Milestone</a> <li><a href="./Gitlab/Entities/Project.html">Gitlab::Entities::Project</a> <li><a href="./Gitlab/Entities/ProjectMember.html">Gitlab::Entities::ProjectMember</a> <li><a href="./Gitlab/Entities/ProjectSnippet.html">Gitlab::Entities::ProjectSnippet</a> <li><a href="./Gitlab/Entities/RepoCommit.html">Gitlab::Entities::RepoCommit</a> <li><a href="./Gitlab/Entities/RepoObject.html">Gitlab::Entities::RepoObject</a> <li><a href="./Gitlab/Entities/SSHKey.html">Gitlab::Entities::SSHKey</a> <li><a href="./Gitlab/Entities/User.html">Gitlab::Entities::User</a> <li><a href="./Gitlab/Entities/UserBasic.html">Gitlab::Entities::UserBasic</a> <li><a href="./Gitlab/Entities/UserLogin.html">Gitlab::Entities::UserLogin</a> <li><a href="./Gitlab/FileEditor.html">Gitlab::FileEditor</a> <li><a href="./Gitlab/GitLogger.html">Gitlab::GitLogger</a> <li><a href="./Gitlab/Gitolite.html">Gitlab::Gitolite</a> <li><a href="./Gitlab/Gitolite/AccessDenied.html">Gitlab::Gitolite::AccessDenied</a> <li><a href="./Gitlab/GitoliteConfig.html">Gitlab::GitoliteConfig</a> <li><a href="./Gitlab/GitoliteConfig/PullError.html">Gitlab::GitoliteConfig::PullError</a> <li><a href="./Gitlab/GitoliteConfig/PushError.html">Gitlab::GitoliteConfig::PushError</a> <li><a href="./Gitlab/GraphCommit.html">Gitlab::GraphCommit</a> <li><a href="./Gitlab/InlineDiff.html">Gitlab::InlineDiff</a> <li><a href="./Gitlab/Issues.html">Gitlab::Issues</a> <li><a href="./Gitlab/Logger.html">Gitlab::Logger</a> <li><a href="./Gitlab/Markdown.html">Gitlab::Markdown</a> <li><a href="./Gitlab/Merge.html">Gitlab::Merge</a> <li><a href="./Gitlab/Milestones.html">Gitlab::Milestones</a> <li><a href="./Gitlab/Projects.html">Gitlab::Projects</a> <li><a href="./Gitlab/Satellite.html">Gitlab::Satellite</a> <li><a href="./Gitlab/Session.html">Gitlab::Session</a> <li><a href="./Gitlab/Theme.html">Gitlab::Theme</a> <li><a href="./Gitlab/Users.html">Gitlab::Users</a> <li><a href="./Admin.html">Admin</a> <li><a href="./Admin/DashboardController.html">Admin::DashboardController</a> <li><a href="./Admin/GroupsController.html">Admin::GroupsController</a> <li><a href="./Admin/HooksController.html">Admin::HooksController</a> <li><a href="./Admin/LogsController.html">Admin::LogsController</a> <li><a href="./Admin/ProjectsController.html">Admin::ProjectsController</a> <li><a href="./Admin/ResqueController.html">Admin::ResqueController</a> <li><a href="./Admin/TeamMembersController.html">Admin::TeamMembersController</a> <li><a href="./Admin/UsersController.html">Admin::UsersController</a> <li><a href="./Notes.html">Notes</a> <li><a href="./Notes/CreateContext.html">Notes::CreateContext</a> <li><a href="./Notes/LoadContext.html">Notes::LoadContext</a> <li><a href="./Redcarpet.html">Redcarpet</a> <li><a href="./Redcarpet/Render.html">Redcarpet::Render</a> <li><a href="./Redcarpet/Render/GitlabHTML.html">Redcarpet::Render::GitlabHTML</a> <li><a href="./ExtractsPath.html">ExtractsPath</a> <li><a href="./ExtractsPath/InvalidPathError.html">ExtractsPath::InvalidPathError</a> <li><a href="./FileSizeValidator.html">FileSizeValidator</a> <li><a href="./FileSizeValidator/Helper.html">FileSizeValidator::Helper</a> <li><a href="./Grack.html">Grack</a> <li><a href="./Grack/Auth.html">Grack::Auth</a> <li><a href="./IssueCommonality.html">IssueCommonality</a> <li><a href="./IssueCommonality/ClassMethods.html">IssueCommonality::ClassMethods</a> <li><a href="./StaticModel.html">StaticModel</a> <li><a href="./StaticModel/ClassMethods.html">StaticModel::ClassMethods</a> <li><a href="./Ability.html">Ability</a> <li><a href="./Account.html">Account</a> <li><a href="./ActivityObserver.html">ActivityObserver</a> <li><a href="./AdminController.html">AdminController</a> <li><a href="./ApplicationController.html">ApplicationController</a> <li><a href="./ApplicationDecorator.html">ApplicationDecorator</a> <li><a href="./ApplicationHelper.html">ApplicationHelper</a> <li><a href="./AttachmentUploader.html">AttachmentUploader</a> <li><a href="./Authority.html">Authority</a> <li><a href="./BaseContext.html">BaseContext</a> <li><a href="./BlameController.html">BlameController</a> <li><a href="./BlobController.html">BlobController</a> <li><a href="./Commit.html">Commit</a> <li><a href="./CommitController.html">CommitController</a> <li><a href="./CommitDecorator.html">CommitDecorator</a> <li><a href="./CommitLoadContext.html">CommitLoadContext</a> <li><a href="./CommitsController.html">CommitsController</a> <li><a href="./CommitsHelper.html">CommitsHelper</a> <li><a href="./CompareController.html">CompareController</a> <li><a href="./DashboardController.html">DashboardController</a> <li><a href="./DeployKeysController.html">DeployKeysController</a> <li><a href="./ErrorsController.html">ErrorsController</a> <li><a href="./Event.html">Event</a> <li><a href="./EventDecorator.html">EventDecorator</a> <li><a href="./EventsHelper.html">EventsHelper</a> <li><a href="./GitHost.html">GitHost</a> <li><a href="./GitlabMarkdownHelper.html">GitlabMarkdownHelper</a> <li><a href="./Group.html">Group</a> <li><a href="./GroupsController.html">GroupsController</a> <li><a href="./HelpController.html">HelpController</a> <li><a href="./HooksController.html">HooksController</a> <li><a href="./Issue.html">Issue</a> <li><a href="./IssueObserver.html">IssueObserver</a> <li><a href="./IssuesBulkUpdateContext.html">IssuesBulkUpdateContext</a> <li><a href="./IssuesController.html">IssuesController</a> <li><a href="./IssuesHelper.html">IssuesHelper</a> <li><a href="./IssuesListContext.html">IssuesListContext</a> <li><a href="./Key.html">Key</a> <li><a href="./KeyObserver.html">KeyObserver</a> <li><a href="./KeysController.html">KeysController</a> <li><a href="./LabelsController.html">LabelsController</a> <li><a href="./MergeRequest.html">MergeRequest</a> <li><a href="./MergeRequestObserver.html">MergeRequestObserver</a> <li><a href="./MergeRequestsController.html">MergeRequestsController</a> <li><a href="./MergeRequestsHelper.html">MergeRequestsHelper</a> <li><a href="./MergeRequestsLoadContext.html">MergeRequestsLoadContext</a> <li><a href="./Milestone.html">Milestone</a> <li><a href="./MilestonesController.html">MilestonesController</a> <li><a href="./Note.html">Note</a> <li><a href="./NoteObserver.html">NoteObserver</a> <li><a href="./NotesController.html">NotesController</a> <li><a href="./NotesHelper.html">NotesHelper</a> <li><a href="./Notify.html">Notify</a> <li><a href="./OmniauthCallbacksController.html">OmniauthCallbacksController</a> <li><a href="./PostReceive.html">PostReceive</a> <li><a href="./ProfileController.html">ProfileController</a> <li><a href="./ProfileHelper.html">ProfileHelper</a> <li><a href="./Project.html">Project</a> <li><a href="./ProjectHook.html">ProjectHook</a> <li><a href="./ProjectObserver.html">ProjectObserver</a> <li><a href="./ProjectResourceController.html">ProjectResourceController</a> <li><a href="./ProjectsController.html">ProjectsController</a> <li><a href="./ProjectsHelper.html">ProjectsHelper</a> <li><a href="./ProtectedBranch.html">ProtectedBranch</a> <li><a href="./ProtectedBranchesController.html">ProtectedBranchesController</a> <li><a href="./PushEvent.html">PushEvent</a> <li><a href="./PushObserver.html">PushObserver</a> <li><a href="./RefsController.html">RefsController</a> <li><a href="./RepositoriesController.html">RepositoriesController</a> <li><a href="./Repository.html">Repository</a> <li><a href="./SearchContext.html">SearchContext</a> <li><a href="./SearchController.html">SearchController</a> <li><a href="./Snippet.html">Snippet</a> <li><a href="./SnippetsController.html">SnippetsController</a> <li><a href="./SnippetsHelper.html">SnippetsHelper</a> <li><a href="./SystemHook.html">SystemHook</a> <li><a href="./SystemHookObserver.html">SystemHookObserver</a> <li><a href="./SystemHookWorker.html">SystemHookWorker</a> <li><a href="./TabHelper.html">TabHelper</a> <li><a href="./TagsHelper.html">TagsHelper</a> <li><a href="./Team.html">Team</a> <li><a href="./TeamMembersController.html">TeamMembersController</a> <li><a href="./TestHookContext.html">TestHookContext</a> <li><a href="./Tree.html">Tree</a> <li><a href="./TreeController.html">TreeController</a> <li><a href="./TreeDecorator.html">TreeDecorator</a> <li><a href="./TreeHelper.html">TreeHelper</a> <li><a href="./User.html">User</a> <li><a href="./UserObserver.html">UserObserver</a> <li><a href="./UsersProject.html">UsersProject</a> <li><a href="./UsersProjectObserver.html">UsersProjectObserver</a> <li><a href="./Votes.html">Votes</a> <li><a href="./WebHook.html">WebHook</a> <li><a href="./Wiki.html">Wiki</a> <li><a href="./WikisController.html">WikisController</a> </ul> </nav> </div> </nav> <div id="documentation"> <h1 class="class">class MergeRequest</h1> <div id="description" class="description"> </div><!-- description --> <section id="5Buntitled-5D" class="documentation-section"> <!-- Constants --> <section id="constants-list" class="section"> <h3 class="section-header">Constants</h3> <dl> <dt id="BROKEN_DIFF">BROKEN_DIFF <dd class="description"> <dt id="CANNOT_BE_MERGED">CANNOT_BE_MERGED <dd class="description"> <dt id="CAN_BE_MERGED">CAN_BE_MERGED <dd class="description"> <dt id="UNCHECKED">UNCHECKED <dd class="description"> </dl> </section> <!-- Attributes --> <section id="attribute-method-details" class="method-section section"> <h3 class="section-header">Attributes</h3> <div id="attribute-i-should_remove_source_branch" class="method-detail"> <div class="method-heading attribute-method-heading"> <span class="method-name">should_remove_source_branch</span><span class="attribute-access-type">[RW]</span> </div> <div class="method-description"> </div> </div> </section><!-- attribute-method-details --> <!-- Methods --> <section id="public-class-5Buntitled-5D-method-details" class="method-section section"> <h3 class="section-header">Public Class Methods</h3> <div id="method-c-find_all_by_branch" class="method-detail "> <div class="method-heading"> <span class="method-name">find_all_by_branch</span><span class="method-args">(branch_name)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="find_all_by_branch-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 25</span> <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">find_all_by_branch</span>(<span class="ruby-identifier">branch_name</span>) <span class="ruby-identifier">where</span>(<span class="ruby-string">"source_branch LIKE :branch OR target_branch LIKE :branch"</span>, <span class="ruby-identifier">branch</span><span class="ruby-operator">:</span> <span class="ruby-identifier">branch_name</span>) <span class="ruby-keyword">end</span></pre> </div><!-- find_all_by_branch-source --> </div> </div><!-- find_all_by_branch-method --> </section><!-- public-class-method-details --> <section id="public-instance-5Buntitled-5D-method-details" class="method-section section"> <h3 class="section-header">Public Instance Methods</h3> <div id="method-i-automerge-21" class="method-detail "> <div class="method-heading"> <span class="method-name">automerge!</span><span class="method-args">(current_user)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="automerge-21-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 169</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">automerge!</span>(<span class="ruby-identifier">current_user</span>) <span class="ruby-keyword">if</span> <span class="ruby-constant">Gitlab</span><span class="ruby-operator">::</span><span class="ruby-constant">Merge</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">current_user</span>).<span class="ruby-identifier">merge!</span> <span class="ruby-operator">&&</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">unmerged_commits</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>) <span class="ruby-keyword">true</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">rescue</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">mark_as_unmergable</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">end</span></pre> </div><!-- automerge-21-source --> </div> </div><!-- automerge-21-method --> <div id="method-i-broken_diffs-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">broken_diffs?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="broken_diffs-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 86</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">broken_diffs?</span> <span class="ruby-identifier">diffs</span> <span class="ruby-operator">==</span> [<span class="ruby-constant">BROKEN_DIFF</span>] <span class="ruby-keyword">end</span></pre> </div><!-- broken_diffs-3F-source --> </div> </div><!-- broken_diffs-3F-method --> <div id="method-i-can_be_merged-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">can_be_merged?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="can_be_merged-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 58</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">can_be_merged?</span> <span class="ruby-identifier">state</span> <span class="ruby-operator">==</span> <span class="ruby-constant">CAN_BE_MERGED</span> <span class="ruby-keyword">end</span></pre> </div><!-- can_be_merged-3F-source --> </div> </div><!-- can_be_merged-3F-method --> <div id="method-i-check_if_can_be_merged" class="method-detail "> <div class="method-heading"> <span class="method-name">check_if_can_be_merged</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="check_if_can_be_merged-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 62</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">check_if_can_be_merged</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">state</span> = <span class="ruby-keyword">if</span> <span class="ruby-constant">Gitlab</span><span class="ruby-operator">::</span><span class="ruby-constant">Merge</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword">self</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">author</span>).<span class="ruby-identifier">can_be_merged?</span> <span class="ruby-constant">CAN_BE_MERGED</span> <span class="ruby-keyword">else</span> <span class="ruby-constant">CANNOT_BE_MERGED</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span></pre> </div><!-- check_if_can_be_merged-source --> </div> </div><!-- check_if_can_be_merged-method --> <div id="method-i-closed_event" class="method-detail "> <div class="method-heading"> <span class="method-name">closed_event</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="closed_event-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 114</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">closed_event</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">project</span>.<span class="ruby-identifier">events</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">target_id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">target_type</span><span class="ruby-operator">:</span> <span class="ruby-string">"MergeRequest"</span>, <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-constant">Event</span><span class="ruby-operator">::</span><span class="ruby-constant">Closed</span>).<span class="ruby-identifier">last</span> <span class="ruby-keyword">end</span></pre> </div><!-- closed_event-source --> </div> </div><!-- closed_event-method --> <div id="method-i-commits" class="method-detail "> <div class="method-heading"> <span class="method-name">commits</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="commits-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 118</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">commits</span> <span class="ruby-identifier">st_commits</span> <span class="ruby-operator">||</span> [] <span class="ruby-keyword">end</span></pre> </div><!-- commits-source --> </div> </div><!-- commits-method --> <div id="method-i-diffs" class="method-detail "> <div class="method-heading"> <span class="method-name">diffs</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="diffs-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 71</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">diffs</span> <span class="ruby-identifier">st_diffs</span> <span class="ruby-operator">||</span> [] <span class="ruby-keyword">end</span></pre> </div><!-- diffs-source --> </div> </div><!-- diffs-method --> <div id="method-i-human_state" class="method-detail "> <div class="method-heading"> <span class="method-name">human_state</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="human_state-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 29</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">human_state</span> <span class="ruby-identifier">states</span> = { <span class="ruby-constant">CAN_BE_MERGED</span> =<span class="ruby-operator">></span> <span class="ruby-string">"can_be_merged"</span>, <span class="ruby-constant">CANNOT_BE_MERGED</span> =<span class="ruby-operator">></span> <span class="ruby-string">"cannot_be_merged"</span>, <span class="ruby-constant">UNCHECKED</span> =<span class="ruby-operator">></span> <span class="ruby-string">"unchecked"</span> } <span class="ruby-identifier">states</span>[<span class="ruby-keyword">self</span>.<span class="ruby-identifier">state</span>] <span class="ruby-keyword">end</span></pre> </div><!-- human_state-source --> </div> </div><!-- human_state-method --> <div id="method-i-last_commit" class="method-detail "> <div class="method-heading"> <span class="method-name">last_commit</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="last_commit-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 102</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">last_commit</span> <span class="ruby-identifier">commits</span>.<span class="ruby-identifier">first</span> <span class="ruby-keyword">end</span></pre> </div><!-- last_commit-source --> </div> </div><!-- last_commit-method --> <div id="method-i-mark_as_merged-21" class="method-detail "> <div class="method-heading"> <span class="method-name">mark_as_merged!</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="mark_as_merged-21-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 131</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">mark_as_merged!</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">merged</span> = <span class="ruby-keyword">true</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">closed</span> = <span class="ruby-keyword">true</span> <span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span></pre> </div><!-- mark_as_merged-21-source --> </div> </div><!-- mark_as_merged-21-method --> <div id="method-i-mark_as_unchecked" class="method-detail "> <div class="method-heading"> <span class="method-name">mark_as_unchecked</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="mark_as_unchecked-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 53</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">mark_as_unchecked</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">state</span> = <span class="ruby-constant">UNCHECKED</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span></pre> </div><!-- mark_as_unchecked-source --> </div> </div><!-- mark_as_unchecked-method --> <div id="method-i-mark_as_unmergable" class="method-detail "> <div class="method-heading"> <span class="method-name">mark_as_unmergable</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="mark_as_unmergable-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 137</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">mark_as_unmergable</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">state</span> = <span class="ruby-constant">CANNOT_BE_MERGED</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span></pre> </div><!-- mark_as_unmergable-source --> </div> </div><!-- mark_as_unmergable-method --> <div id="method-i-merge-21" class="method-detail "> <div class="method-heading"> <span class="method-name">merge!</span><span class="method-args">(user_id)</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="merge-21-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 158</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">user_id</span>) <span class="ruby-keyword">self</span>.<span class="ruby-identifier">mark_as_merged!</span> <span class="ruby-constant">Event</span>.<span class="ruby-identifier">create</span>( <span class="ruby-identifier">project</span><span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">project</span>, <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-constant">Event</span><span class="ruby-operator">::</span><span class="ruby-constant">Merged</span>, <span class="ruby-identifier">target_id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">target_type</span><span class="ruby-operator">:</span> <span class="ruby-string">"MergeRequest"</span>, <span class="ruby-identifier">author_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user_id</span> ) <span class="ruby-keyword">end</span></pre> </div><!-- merge-21-source --> </div> </div><!-- merge-21-method --> <div id="method-i-merge_event" class="method-detail "> <div class="method-heading"> <span class="method-name">merge_event</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="merge_event-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 110</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">merge_event</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">project</span>.<span class="ruby-identifier">events</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">target_id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">target_type</span><span class="ruby-operator">:</span> <span class="ruby-string">"MergeRequest"</span>, <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-constant">Event</span><span class="ruby-operator">::</span><span class="ruby-constant">Merged</span>).<span class="ruby-identifier">last</span> <span class="ruby-keyword">end</span></pre> </div><!-- merge_event-source --> </div> </div><!-- merge_event-method --> <div id="method-i-merged-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">merged?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="merged-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 106</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">merged?</span> <span class="ruby-identifier">merged</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">merge_event</span> <span class="ruby-keyword">end</span></pre> </div><!-- merged-3F-source --> </div> </div><!-- merged-3F-method --> <div id="method-i-mr_and_commit_notes" class="method-detail "> <div class="method-heading"> <span class="method-name">mr_and_commit_notes</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="mr_and_commit_notes-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 191</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">mr_and_commit_notes</span> <span class="ruby-identifier">commit_ids</span> = <span class="ruby-identifier">commits</span>.<span class="ruby-identifier">map</span>(&<span class="ruby-value">:id</span>) <span class="ruby-constant">Note</span>.<span class="ruby-identifier">where</span>(<span class="ruby-string">"(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND noteable_id IN (:commit_ids))"</span>, <span class="ruby-identifier">mr_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">id</span>, <span class="ruby-identifier">commit_ids</span><span class="ruby-operator">:</span> <span class="ruby-identifier">commit_ids</span>) <span class="ruby-keyword">end</span></pre> </div><!-- mr_and_commit_notes-source --> </div> </div><!-- mr_and_commit_notes-method --> <div id="method-i-open-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">open?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="open-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 127</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">open?</span> <span class="ruby-operator">!</span><span class="ruby-identifier">closed</span> <span class="ruby-keyword">end</span></pre> </div><!-- open-3F-source --> </div> </div><!-- open-3F-method --> <div id="method-i-probably_merged-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">probably_merged?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="probably_merged-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 122</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">probably_merged?</span> <span class="ruby-identifier">unmerged_commits</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">commits</span>.<span class="ruby-identifier">any?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">open?</span> <span class="ruby-keyword">end</span></pre> </div><!-- probably_merged-3F-source --> </div> </div><!-- probably_merged-3F-method --> <div id="method-i-reload_code" class="method-detail "> <div class="method-heading"> <span class="method-name">reload_code</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="reload_code-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 44</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">reload_code</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">reloaded_commits</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">reloaded_diffs</span> <span class="ruby-keyword">end</span></pre> </div><!-- reload_code-source --> </div> </div><!-- reload_code-method --> <div id="method-i-reloaded_commits" class="method-detail "> <div class="method-heading"> <span class="method-name">reloaded_commits</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="reloaded_commits-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 142</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">reloaded_commits</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">open?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">unmerged_commits</span>.<span class="ruby-identifier">any?</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">st_commits</span> = <span class="ruby-identifier">unmerged_commits</span> <span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span> <span class="ruby-identifier">commits</span> <span class="ruby-keyword">end</span></pre> </div><!-- reloaded_commits-source --> </div> </div><!-- reloaded_commits-method --> <div id="method-i-reloaded_diffs" class="method-detail "> <div class="method-heading"> <span class="method-name">reloaded_diffs</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="reloaded_diffs-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 75</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">reloaded_diffs</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">open?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">unmerged_diffs</span>.<span class="ruby-identifier">any?</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">st_diffs</span> = <span class="ruby-identifier">unmerged_diffs</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Grit</span><span class="ruby-operator">::</span><span class="ruby-constant">Git</span><span class="ruby-operator">::</span><span class="ruby-constant">GitTimeout</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">st_diffs</span> = [<span class="ruby-constant">BROKEN_DIFF</span>] <span class="ruby-keyword">self</span>.<span class="ruby-identifier">save</span> <span class="ruby-keyword">end</span></pre> </div><!-- reloaded_diffs-source --> </div> </div><!-- reloaded_diffs-method --> <div id="method-i-to_raw" class="method-detail "> <div class="method-heading"> <span class="method-name">to_raw</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="to_raw-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 179</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">to_raw</span> <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span>(<span class="ruby-constant">Rails</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">"tmp"</span>, <span class="ruby-string">"patches"</span>)) <span class="ruby-identifier">patch_path</span> = <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">"tmp"</span>, <span class="ruby-string">"patches"</span>, <span class="ruby-node">"merge_request_#{self.id}.patch"</span>) <span class="ruby-identifier">from</span> = <span class="ruby-identifier">commits</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">id</span> <span class="ruby-identifier">to</span> = <span class="ruby-identifier">source_branch</span> <span class="ruby-identifier">project</span>.<span class="ruby-identifier">repo</span>.<span class="ruby-identifier">git</span>.<span class="ruby-identifier">run</span>(<span class="ruby-string">''</span>, <span class="ruby-string">"format-patch"</span> , <span class="ruby-node">" > #{patch_path.to_s}"</span>, {}, [<span class="ruby-node">"#{from}..#{to}"</span>, <span class="ruby-string">"--stdout"</span>]) <span class="ruby-identifier">patch_path</span> <span class="ruby-keyword">end</span></pre> </div><!-- to_raw-source --> </div> </div><!-- to_raw-method --> <div id="method-i-unchecked-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">unchecked?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="unchecked-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 49</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">unchecked?</span> <span class="ruby-identifier">state</span> <span class="ruby-operator">==</span> <span class="ruby-constant">UNCHECKED</span> <span class="ruby-keyword">end</span></pre> </div><!-- unchecked-3F-source --> </div> </div><!-- unchecked-3F-method --> <div id="method-i-unmerged_commits" class="method-detail "> <div class="method-heading"> <span class="method-name">unmerged_commits</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="unmerged_commits-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 150</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">unmerged_commits</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">project</span>.<span class="ruby-identifier">repo</span>. <span class="ruby-identifier">commits_between</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">target_branch</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">source_branch</span>). <span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-constant">Commit</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">c</span>)}. <span class="ruby-identifier">sort_by</span>(&<span class="ruby-value">:created_at</span>). <span class="ruby-identifier">reverse</span> <span class="ruby-keyword">end</span></pre> </div><!-- unmerged_commits-source --> </div> </div><!-- unmerged_commits-method --> <div id="method-i-unmerged_diffs" class="method-detail "> <div class="method-heading"> <span class="method-name">unmerged_diffs</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="unmerged_diffs-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 94</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">unmerged_diffs</span> <span class="ruby-comment"># Only show what is new in the source branch compared to the target branch, not the other way around.</span> <span class="ruby-comment"># The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)</span> <span class="ruby-comment"># From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"</span> <span class="ruby-identifier">common_commit</span> = <span class="ruby-identifier">project</span>.<span class="ruby-identifier">repo</span>.<span class="ruby-identifier">git</span>.<span class="ruby-identifier">native</span>(<span class="ruby-value">:merge_base</span>, {}, [<span class="ruby-identifier">target_branch</span>, <span class="ruby-identifier">source_branch</span>]).<span class="ruby-identifier">strip</span> <span class="ruby-identifier">diffs</span> = <span class="ruby-identifier">project</span>.<span class="ruby-identifier">repo</span>.<span class="ruby-identifier">diff</span>(<span class="ruby-identifier">common_commit</span>, <span class="ruby-identifier">source_branch</span>) <span class="ruby-keyword">end</span></pre> </div><!-- unmerged_diffs-source --> </div> </div><!-- unmerged_diffs-method --> <div id="method-i-valid_diffs-3F" class="method-detail "> <div class="method-heading"> <span class="method-name">valid_diffs?</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="valid_diffs-3F-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 90</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">valid_diffs?</span> <span class="ruby-operator">!</span><span class="ruby-identifier">broken_diffs?</span> <span class="ruby-keyword">end</span></pre> </div><!-- valid_diffs-3F-source --> </div> </div><!-- valid_diffs-3F-method --> <div id="method-i-validate_branches" class="method-detail "> <div class="method-heading"> <span class="method-name">validate_branches</span><span class="method-args">()</span> <span class="method-click-advice">click to toggle source</span> </div> <div class="method-description"> <div class="method-source-code" id="validate_branches-source"> <pre><span class="ruby-comment"># File app/models/merge_request.rb, line 38</span> <span class="ruby-keyword">def</span> <span class="ruby-identifier">validate_branches</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">target_branch</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">source_branch</span> <span class="ruby-identifier">errors</span>.<span class="ruby-identifier">add</span> <span class="ruby-value">:base</span>, <span class="ruby-string">"You can not use same branch for source and target branches"</span> <span class="ruby-keyword">end</span> <span class="ruby-keyword">end</span></pre> </div><!-- validate_branches-source --> </div> </div><!-- validate_branches-method --> </section><!-- public-instance-method-details --> </section><!-- 5Buntitled-5D --> </div><!-- documentation --> <footer id="validator-badges"> <p><a href="http://validator.w3.org/check/referer">[Validate]</a> <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12. <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3. </footer>