<odoo>

    <record id="form_repository" model="ir.ui.view">
        <field name="name">Repository form</field>
        <field name="model">runbot_merge.repository</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <div class="oe_title">
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="group_id" string="Accessible to"/>
                        </group>
                        <group>
                            <field name="branch_filter"/>
                        </group>
                    </group>
                    <separator string="Required Statuses"/>
                    <field name="status_ids">
                        <tree editable="bottom">
                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open status"/>
                            <field name="context"/>
                            <field name="branch_filter"/>
                            <field name="prs"/>
                            <field name="stagings"/>
                        </tree>
                    </field>
                </sheet>
            </form>
        </field>
    </record>
    <record id="runbot_merge_branch_form" model="ir.ui.view">
        <field name="name">Branch Form</field>
        <field name="model">runbot_merge.branch</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <div class="oe_title">
                        <h1><field name="name"/></h1>
                    </div>
                    <group>
                        <group>
                            <field name="project_id" readonly="1"/>
                            <field name="sequence" readonly="1"/>
                        </group>
                        <group>
                            <field name="active"/>
                            <field name="staging_enabled"/>
                        </group>
                    </group>
                    <separator string="Stagings"/>
                    <group>
                        <field name="active_staging_id"/>
                    </group>
                    <field name="staging_ids" nolabel="1" readonly="1">
                        <tree default_order="staged_at desc">
                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open staging"/>
                            <field name="id"/>
                            <field name="staged_at"/>
                            <field name="state"/>
                        </tree>
                    </field>
                </sheet>
            </form>
        </field>
    </record>

    <record id="runbot_merge_action_projects" model="ir.actions.act_window">
        <field name="name">Projects</field>
        <field name="res_model">runbot_merge.project</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record id="runbot_merge_action_prs" model="ir.actions.act_window">
        <field name="name">Pull Requests</field>
        <field name="res_model">runbot_merge.pull_requests</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'search_default_open': True}</field>
    </record>
    <record id="runbot_merge_search_prs" model="ir.ui.view">
        <field name="name">PR search</field>
        <field name="model">runbot_merge.pull_requests</field>
        <field name="arch" type="xml">
            <search>
                <filter
                    name="open" string="Open"
                    domain="[('state', 'not in', ['merged', 'closed'])]"
                />
                <field name="label"/>
                <field name="number"/>
                <field name="author"/>
                <field name="target"/>
                <field name="repository"/>
                <field name="state"/>

                <group>
                    <filter string="Target" name="target_" context="{'group_by':'target'}"/>
                    <filter string="Repository" name="repo_" context="{'group_by':'repository'}"/>
                    <filter string="State" name="state_" context="{'group_by':'state'}"/>
                    <filter string="Priority" name="priority_" context="{'group_by':'priority'}"/>
                </group>
            </search>
        </field>
    </record>
    <record id="runbot_merge_tree_prs" model="ir.ui.view">
        <field name="name">PR tree</field>
        <field name="model">runbot_merge.pull_requests</field>
        <field name="arch" type="xml">
            <tree>
                <field name="repository"/>
                <field name="number"/>
                <field name="target"/>
                <field name="state"/>
                <field name="author"/>
                <field name="reviewed_by"/>
                <field name="write_date"/>
            </tree>
        </field>
    </record>
    <record id="runbot_merge_form_prs" model="ir.ui.view">
        <field name="name">PR form</field>
        <field name="model">runbot_merge.pull_requests</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <div class="d-flex gap-1">
                        <button type="object" name="button_split" string="Split Off"/>
                        <field name="github_url" widget="url" class="btn btn-secondary mb-0" text="Github"/>
                        <field name="url" widget="url" class="btn btn-secondary mb-0" text="Frontend"/>
                    </div>
                </header>
                <sheet>
                    <field name="project" invisible="1"/>
                    <field name="target_sequence" invisible="1"/>
                    <div class="oe_title" colspan="2">
                        <h1>
                            <field name="repository" readonly="True"/>#<field name="number" readonly="True"/>
                        </h1>
                        <h2>
                            <field name="state"/>
                            <span invisible="state == 'merged' or not blocked">
                                <!--
                                The web client forces char fields to take 100%
                                width in all situations without (as far as I
                                can tell) opt out, if the view is in edition
                                mode. Which is now always the case for form views.
                                -->
                                (blocked: <field name="blocked" class="w-auto"/>)
                            </span>
                            <span invisible="state != 'merged'">
                                (<field name="merge_date" readonly="True"/>)
                            </span>
                        </h2>
                    </div>
                    <!-- main PR metadata -->
                    <group name="metadata">
                        <group>
                            <field name="batch_id"/>
                            <field name="target"/>
                        </group>
                        <group>
                            <field name="author"/>
                            <field name="head"/>
                        </group>
                    </group>
                    <notebook>
                        <page name="state" string="State">
                            <group>
                                <group>
                                    <field name="reviewed_by"/>
                                    <field name="closed"/>
                                    <field name="error"/>
                                </group>
                                <group>
                                    <field name="status"/>
                                    <details colspan="4">
                                        <summary>Commit Statuses</summary>

                                        <field name="statuses"/>
                                    </details>
                                    <details colspan="4">
                                        <summary>Overrides</summary>
                                        <field name="overrides"/>
                                    </details>
                                </group>
                            </group>
                        </page>
                        <page name="configuration" string="Configuration">
                            <group>
                                <group>
                                    <field name="merge_method"/>
                                    <field name="squash"/>
                                    <field name="draft"/>
                                </group>
                                <group>
                                    <field name="priority"/>
                                    <field name="skipchecks" widget="boolean_toggle"/>
                                    <field name="cancel_staging" widget="boolean_toggle"/>
                                </group>
                            </group>
                            <group string="Delegates">
                                <group colspan="4">
                                    <field colspan="2" name="delegates" nolabel="1">
                                        <tree>
                                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open partner"/>
                                            <field name="name"/>
                                            <field name="github_login"/>
                                        </tree>
                                    </field>
                                </group>
                            </group>
                        </page>
                        <page name="stagings" string="Staging History">
                            <group>
                                <group colspan="4">
                                    <field colspan="2" name="staging_ids" nolabel="1" readonly="1">
                                        <tree>
                                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open staging"/>
                                            <field name="staged_at"/>
                                            <field name="state"/>
                                            <field name="reason"/>
                                        </tree>
                                    </field>
                                </group>
                            </group>
                        </page>
                        <page name="porting" string="Forward-Porting">
                            <group>
                                <group>
                                    <field name="limit_id" domain="[('project_id', '=', project), ('sequence', '&lt;=', target_sequence)]"/>
                                    <field string="Original PR" name="source_id"/>
                                    <field name="parent_id"/>
                                    <field
                                        invisible="source_id and not parent_id"
                                        string="Detached because" name="detach_reason" readonly="1"/>
                                </group>
                              <group>
                                <field colspan="2" name="forwardport_ids" nolabel="1" readonly="True">
                                  <tree>
                                    <button type="object" name="get_formview_action" icon="fa-external-link" title="open PR"/>
                                    <field name="target" string="Branch"/>
                                    <field name="number"/>
                                  </tree>
                                </field>
                              </group>
                            </group>
                        </page>
                    </notebook>
                    <!-- influencers -->
                    <group string="Message">
                        <group colspan="4">
                            <field colspan="2" name="message" nolabel="1" readonly="1"/>
                        </group>
                    </group>
                </sheet>
                <div class="oe_chatter">
                    <field name="message_follower_ids" widget="mail_followers"/>
                    <field name="message_ids" widget="mail_thread"/>
                </div>
            </form>
        </field>
    </record>

    <record id="runbot_merge_pull_requests_split_off_form" model="ir.ui.view">
        <field name="name">Split Off Form</field>
        <field name="model">runbot_merge.pull_requests.split_off</field>
        <field name="arch" type="xml">
            <form>
                <field name="new_label" colspan="4"/>
                <footer>
                    <button type="object" name="button_apply" string="Apply" class="btn btn-primary"/>
                    <button special="cancel" string="Cancel"  class="btn btn-secondary"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="runbot_merge_action_stagings" model="ir.actions.act_window">
        <field name="name">Stagings</field>
        <field name="res_model">runbot_merge.stagings</field>
        <field name="view_mode">tree,form</field>
        <field name="context">{'search_default_active': True, 'active_test': False}</field>
    </record>
    <record id="runbot_merge_search_stagings" model="ir.ui.view">
        <field name="name">Stagings Search</field>
        <field name="model">runbot_merge.stagings</field>
        <field name="arch" type="xml">
            <search>
                <filter string="Active" name="active"
                        domain="[('active', '=', True)]"/>
                <field name="state"/>
                <field name="target"/>

                <group>
                    <filter string="Target" name="target_" context="{'group_by': 'target'}"/>
                </group>
            </search>
        </field>
    </record>
    <record id="runbot_merge_tree_stagings" model="ir.ui.view">
        <field name="name">Stagings Tree</field>
        <field name="model">runbot_merge.stagings</field>
        <field name="arch" type="xml">
            <tree>
                <field name="target"/>
                <field name="state"/>
            </tree>
        </field>
    </record>
    <record id="runbot_merge_form_stagings" model="ir.ui.view">
        <field name="name">Stagings Form</field>
        <field name="model">runbot_merge.stagings</field>
        <field name="arch" type="xml">
            <form>
                <field name="active" invisible="1"/>
                <header>
                    <button type="object" name="action_cancel" string="Cancel" class="oe_highlight"
                            invisible="not active"
                    />
                </header>
                <sheet>
                    <group>
                        <group>
                            <field name="target"/>
                            <field name="state"/>
                            <field name="reason"/>
                        </group>
                        <group>
                            <field name="staged_at"/>
                            <field string="Staging Duration (seconds)"
                                    name="staging_duration" widget="integer"/>
                        </group>
                    </group>
                    <notebook>
                        <page string="PRs">
                            <group string="Batches">
                                <field name="batch_ids" colspan="4" nolabel="1" readonly="1">
                                    <tree>
                                        <button type="object" name="get_formview_action" icon="fa-external-link" title="open batch"/>
                                        <field name="name"/>
                                        <field name="prs" widget="many2many_tags"/>
                                    </tree>
                                </field>
                            </group>
                            <group string="PRs">
                                <field name="pr_ids" colspan="4" nolabel="1" readonly="1">
                                    <tree>
                                        <button type="object" name="get_formview_action" icon="fa-external-link" title="open pr"/>
                                        <field name="display_name"/>
                                        <field name="github_url" widget="url"/>
                                        <field name="url" widget="url"/>
                                    </tree>
                                </field>
                            </group>
                        </page>
                        <page string="Commits">
                            <group>
                                <group string="Heads">
                                    <field name="head_ids" colspan="2" nolabel="1" readonly="1">
                                        <tree>
                                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open head"/>
                                            <field name="sha"/>
                                        </tree>
                                    </field>
                                </group>
                                <group string="Commits">
                                    <field name="commit_ids" colspan="2" nolabel="1" readonly="1">
                                        <tree>
                                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open commit"/>
                                            <field name="sha"/>
                                        </tree>
                                    </field>
                                </group>
                            </group>
                        </page>
                        <page string="Splits">
                            <field name="child_ids" colspan="4" nolabel="1" readonly="1">
                                <tree>
                                    <button type="object" name="get_formview_action" icon="fa-external-link" title="open pr"/>
                                    <field name="display_name"/>
                                    <field name="state"/>
                                    <field name="reason"/>
                                </tree>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <record id="runbot_merge_action_commits" model="ir.actions.act_window">
        <field name="name">Commit Statuses</field>
        <field name="res_model">runbot_merge.commit</field>
        <field name="view_mode">tree,form</field>
    </record>
    <record id="runbot_merge_commits_search" model="ir.ui.view">
        <field name="name">commits search</field>
        <field name="model">runbot_merge.commit</field>
        <field name="arch" type="xml">
            <search>
                <field name="sha" operator="="/>
            </search>
        </field>
    </record>
    <record id="runbot_merge_commits_tree" model="ir.ui.view">
        <field name="name">commits list</field>
        <field name="model">runbot_merge.commit</field>
        <field name="arch" type="xml">
            <tree>
                <field name="sha"/>
            </tree>
        </field>
    </record>
    <record id="runbot_merge_commits_form" model="ir.ui.view">
        <field name="name">commits form</field>
        <field name="model">runbot_merge.commit</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <div class="oe_title">
                        <h1><field name="sha"/></h1>
                    </div>
                    <field name="statuses" widget="json"/>
                    <separator string="Pull Requests"/>
                    <field name="pull_requests" nolabel="1">
                        <tree>
                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open pr"/>
                            <field name="display_name"/>
                            <field name="state"/>
                        </tree>
                    </field>
                    <separator string="Stagings (commits)"/>
                    <field name="commit_ids" nolabel="1" readonly="1">
                        <tree>
                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open commit"/>
                            <field name="target"/>
                            <field name="id"/>
                            <field name="staged_at"/>
                            <field name="state"/>
                        </tree>
                    </field>
                    <separator string="Stagings (heads)"/>
                    <field name="head_ids" nolabel="1" readonly="1">
                        <tree>
                            <button type="object" name="get_formview_action" icon="fa-external-link" title="open head"/>
                            <field name="target"/>
                            <field name="id"/>
                            <field name="staged_at"/>
                            <field name="state"/>
                        </tree>
                    </field>
                </sheet>
            </form>
        </field>
    </record>

    <menuitem name="Mergebot" id="runbot_merge_menu">
        <menuitem name="Pull Requests" id="runbot_merge_menu_prs"
                  action="runbot_merge_action_prs" sequence="5"/>
        <menuitem name="Stagings" id="runbot_merge_menu_stagings"
                  action="runbot_merge_action_stagings" sequence="8"/>
        <menuitem name="Projects" id="runbot_merge_menu_project"
                  action="runbot_merge_action_projects"/>
        <menuitem name="Batches" id="runbot_merge_menu_batches"
                  action="runbot_merge_action_batches"/>
        <menuitem name="Commits" id="runbot_merge_menu_commits"
                  action="runbot_merge_action_commits"/>
    </menuitem>
</odoo>
