Skip to content

Commit

Permalink
DEVPROD-4544: Add api for using --repeat-patch patch command. (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
johndaniels authored and Ubuntu committed May 28, 2024
1 parent 14c0259 commit 086552e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
35 changes: 31 additions & 4 deletions _modules/evergreen/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h1>Source code for evergreen.api</h1><div class="highlight"><pre>
<span class="p">}</span>
<span class="p">)</span>

<span class="n">EVERGREEN_URL_REGEX</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(https?)://evergreen\..*?(?=</span><span class="se">\\</span><span class="s2">n)&quot;</span><span class="p">)</span>
<span class="n">EVERGREEN_URL_REGEX</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(https?)://evergreen\..*?(?=\n)&quot;</span><span class="p">)</span>
<span class="n">EVERGREEN_PATCH_ID_REGEX</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(?&lt;=ID : )\w</span><span class="si">{24}</span><span class="s2">&quot;</span><span class="p">)</span>


Expand Down Expand Up @@ -945,7 +945,7 @@ <h1>Source code for evergreen.api</h1><div class="highlight"><pre>
<span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_url</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;/projects/</span><span class="si">{</span><span class="n">project_id</span><span class="si">}</span><span class="s2">/task_reliability&quot;</span><span class="p">)</span>
<span class="n">task_reliability_scores</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_paginate</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="p">)</span>
<span class="k">return</span> <span class="p">[</span>
<span class="n">TaskReliability</span><span class="p">(</span><span class="n">task_reliability</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span> <span class="k">for</span> <span class="n">task_reliability</span> <span class="ow">in</span> <span class="n">task_reliability_scores</span> <span class="c1"># type: ignore[arg-type]</span>
<span class="n">TaskReliability</span><span class="p">(</span><span class="n">cast</span><span class="p">(</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">],</span> <span class="n">task_reliability</span><span class="p">),</span> <span class="bp">self</span><span class="p">)</span> <span class="k">for</span> <span class="n">task_reliability</span> <span class="ow">in</span> <span class="n">task_reliability_scores</span> <span class="c1"># type: ignore[arg-type]</span>
<span class="p">]</span></div>

<div class="viewcode-block" id="EvergreenApi.build_by_id"><a class="viewcode-back" href="../../evergreen.html#evergreen.api.EvergreenApi.build_by_id">[docs]</a> <span class="k">def</span> <span class="nf">build_by_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">build_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Build</span><span class="p">:</span>
Expand Down Expand Up @@ -1034,7 +1034,12 @@ <h1>Source code for evergreen.api</h1><div class="highlight"><pre>
<span class="n">command</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">command</span><span class="si">}</span><span class="s2"> --author </span><span class="si">{</span><span class="n">author</span><span class="si">}</span><span class="s2">&quot;</span>

<span class="n">process</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">capture_output</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">output</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">process</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">process</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="n">output</span><span class="p">:</span>
<span class="c1"># patch-file returns on stderr, but patch returns on stdout,</span>
<span class="c1"># so if stderr is empty, check stdout</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">process</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>

<span class="n">url_match</span> <span class="o">=</span> <span class="n">EVERGREEN_URL_REGEX</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
<span class="n">id_match</span> <span class="o">=</span> <span class="n">EVERGREEN_PATCH_ID_REGEX</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
Expand Down Expand Up @@ -1090,7 +1095,6 @@ <h1>Source code for evergreen.api</h1><div class="highlight"><pre>

<span class="sd"> :param patch_id: The patch_id to base this build on.</span>
<span class="sd"> :param params: The params to pass to the build.</span>
<span class="sd"> :param base: The build&#39;s base commit.</span>
<span class="sd"> :param task: The task(s) to run.</span>
<span class="sd"> :param project: The project to start the build for.</span>
<span class="sd"> :param description: A description of the build.</span>
Expand All @@ -1103,6 +1107,29 @@ <h1>Source code for evergreen.api</h1><div class="highlight"><pre>
<span class="n">command</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;evergreen patch-file --diff-patchId </span><span class="si">{</span><span class="n">patch_id</span><span class="si">}</span><span class="s2"> --description &#39;</span><span class="si">{</span><span class="n">description</span><span class="si">}</span><span class="s2">&#39; --tasks </span><span class="si">{</span><span class="n">task</span><span class="si">}</span><span class="s2"> --variants </span><span class="si">{</span><span class="n">variant</span><span class="si">}</span><span class="s2"> --project </span><span class="si">{</span><span class="n">project</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="n">unpacked_params</span><span class="si">}</span><span class="s2"> -y -f&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_execute_patch_file_command</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">author</span><span class="p">)</span></div>

<div class="viewcode-block" id="EvergreenApi.repeat_patch"><a class="viewcode-back" href="../../evergreen.html#evergreen.api.EvergreenApi.repeat_patch">[docs]</a> <span class="k">def</span> <span class="nf">repeat_patch</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">patch_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">params</span><span class="p">:</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">],</span>
<span class="n">project</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">description</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
<span class="n">author</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">PatchCreationDetails</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Start a patch build based on a diff.</span>

<span class="sd"> :param patch_id: The patch_id whose tasks should be repeated.</span>
<span class="sd"> :param params: The params to pass to the build.</span>
<span class="sd"> :param project: The project to start the build for.</span>
<span class="sd"> :param description: A description of the build.</span>
<span class="sd"> :param author: The author to attribute for the build.</span>
<span class="sd"> :raises Exception: If a build URL is not produced we raise an exception with the output included.</span>
<span class="sd"> :return: The patch creation details.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">unpacked_params</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="sa">f</span><span class="s2">&quot;--param &#39;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s2">=</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">&#39;&quot;</span> <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">params</span><span class="o">.</span><span class="n">items</span><span class="p">()])</span>
<span class="n">command</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;evergreen patch-file --diff-patchId </span><span class="si">{</span><span class="n">patch_id</span><span class="si">}</span><span class="s2"> --repeat-patch </span><span class="si">{</span><span class="n">patch_id</span><span class="si">}</span><span class="s2"> --description &#39;</span><span class="si">{</span><span class="n">description</span><span class="si">}</span><span class="s2">&#39; --project </span><span class="si">{</span><span class="n">project</span><span class="si">}</span><span class="s2"> </span><span class="si">{</span><span class="n">unpacked_params</span><span class="si">}</span><span class="s2"> -y -f&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_execute_patch_file_command</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">author</span><span class="p">)</span></div>

<div class="viewcode-block" id="EvergreenApi.task_by_id"><a class="viewcode-back" href="../../evergreen.html#evergreen.api.EvergreenApi.task_by_id">[docs]</a> <span class="k">def</span> <span class="nf">task_by_id</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">task_id</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
Expand Down
25 changes: 24 additions & 1 deletion evergreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<dd class="field-odd"><ul class="simple">
<li><p><strong>patch_id</strong> – The patch_id to base this build on.</p></li>
<li><p><strong>params</strong> – The params to pass to the build.</p></li>
<li><p><strong>base</strong> – The build’s base commit.</p></li>
<li><p><strong>task</strong> – The task(s) to run.</p></li>
<li><p><strong>project</strong> – The project to start the build for.</p></li>
<li><p><strong>description</strong> – A description of the build.</p></li>
Expand Down Expand Up @@ -849,6 +848,29 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="evergreen.api.EvergreenApi.repeat_patch">
<span class="sig-name descname"><span class="pre">repeat_patch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">patch_id</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">dict</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">,</span></span><span class="w"> </span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">project</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">description</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">author</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#evergreen.patch.PatchCreationDetails" title="evergreen.patch.PatchCreationDetails"><span class="pre">PatchCreationDetails</span></a></span></span><a class="reference internal" href="_modules/evergreen/api.html#EvergreenApi.repeat_patch"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#evergreen.api.EvergreenApi.repeat_patch" title="Permalink to this definition">¶</a></dt>
<dd><p>Start a patch build based on a diff.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>patch_id</strong> – The patch_id whose tasks should be repeated.</p></li>
<li><p><strong>params</strong> – The params to pass to the build.</p></li>
<li><p><strong>project</strong> – The project to start the build for.</p></li>
<li><p><strong>description</strong> – A description of the build.</p></li>
<li><p><strong>author</strong> – The author to attribute for the build.</p></li>
</ul>
</dd>
<dt class="field-even">Raises<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>Exception</strong> – If a build URL is not produced we raise an exception with the output included.</p>
</dd>
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>The patch creation details.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="evergreen.api.EvergreenApi.restart_task">
<span class="sig-name descname"><span class="pre">restart_task</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">task_id</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/evergreen/api.html#EvergreenApi.restart_task"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#evergreen.api.EvergreenApi.restart_task" title="Permalink to this definition">¶</a></dt>
Expand Down Expand Up @@ -5008,6 +5030,7 @@ <h3><a href="index.html">Table of Contents</a></h3>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.permissions_for_user"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.permissions_for_user()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.project_by_id"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.project_by_id()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.recent_versions_by_project"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.recent_versions_by_project()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.repeat_patch"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.repeat_patch()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.restart_task"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.restart_task()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.retrieve_task_log"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.retrieve_task_log()</span></code></a></li>
<li><a class="reference internal" href="#evergreen.api.EvergreenApi.select_tests"><code class="docutils literal notranslate"><span class="pre">EvergreenApi.select_tests()</span></code></a></li>
Expand Down
2 changes: 2 additions & 0 deletions genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,8 @@ <h2 id="R">R</h2>
<li><a href="evergreen.html#evergreen.project.Project.remote_path">remote_path (evergreen.project.Project property)</a>
</li>
<li><a href="evergreen.html#evergreen.resource_type_permissions.RemovablePermission">RemovablePermission (class in evergreen.resource_type_permissions)</a>
</li>
<li><a href="evergreen.html#evergreen.api.EvergreenApi.repeat_patch">repeat_patch() (evergreen.api.EvergreenApi method)</a>
</li>
<li><a href="evergreen.html#evergreen.manifest.ManifestModule.repo">repo (evergreen.manifest.ManifestModule property)</a>

Expand Down
Loading

0 comments on commit 086552e

Please sign in to comment.