@@ -1702,101 +1702,125 @@ $stacktrace
17021702 );
17031703 final name = checkRunEvent.checkRun! .name;
17041704 var success = false ;
1705- if (name == Config .kMergeQueueLockName ||
1706- name == Config .kDashboardCheckName) {
1707- final slug = checkRunEvent.repository! .slug ();
1708- final checkSuiteId = checkRunEvent.checkRun! .checkSuite! .id! ;
1709- log.debug (
1710- '$logCrumb : Requested re-run of "$name " for '
1711- '$slug / $checkSuiteId - ignoring' ,
1712- );
1713- success = true ;
1714- } else if (name == Config .kCiYamlCheckName) {
1715- // The CheckRunEvent.checkRun.pullRequests array is empty for this
1716- // event, so we need to find the matching pull request.
1717- final slug = checkRunEvent.repository! .slug ();
1718- final headSha = checkRunEvent.checkRun! .headSha! ;
1719- final checkSuiteId = checkRunEvent.checkRun! .checkSuite! .id! ;
1720- final pullRequest = await _githubChecksService.findMatchingPullRequest (
1721- slug,
1722- headSha,
1723- checkSuiteId,
1724- );
1725- if (pullRequest != null ) {
1726- log.debug ('Matched PR: ${pullRequest .number } Repo: ${slug .fullName }' );
1727- await triggerPresubmitTargets (pullRequest: pullRequest);
1705+
1706+ final slug = checkRunEvent.repository! .slug ();
1707+
1708+ switch (name) {
1709+ case Config .kMergeQueueLockName:
1710+ final checkSuiteId = checkRunEvent.checkRun! .checkSuite! .id! ;
1711+ log.debug (
1712+ '$logCrumb : Requested re-run of "$name " for '
1713+ '$slug / $checkSuiteId - ignoring' ,
1714+ );
17281715 success = true ;
1729- } else {
1730- log.warn ('No matching PR found for head_sha in check run event.' );
1731- }
1732- } else {
1733- try {
1734- final slug = checkRunEvent.repository! .slug ();
1735- final sha = checkRunEvent.checkRun! .headSha! ;
1736-
1737- // Only merged commits are added to the Database.
1738- // If a commit is found, this must be a postsubmit checkrun.
1739- final fsCommit = await fs.Commit .tryFromFirestoreBySha (
1740- _firestore,
1741- sha: sha,
1716+ case Config .kDashboardCheckName:
1717+ try {
1718+ log.info (
1719+ 'Resetting dashboard checks ${checkRunEvent .checkRun !.id } to in progress' ,
1720+ );
1721+ await _githubChecksService.githubChecksUtil.updateCheckRun (
1722+ _config,
1723+ slug,
1724+ checkRunEvent.checkRun! .toGithubCheckRun (),
1725+ status: CheckRunStatus .inProgress,
1726+ output: const CheckRunOutput (
1727+ title: Config .kDashboardCheckName,
1728+ summary: Scheduler .kDashboardChecksDescription,
1729+ ),
1730+ );
1731+ success = true ;
1732+ } catch (e, s) {
1733+ // We are not going to block on this error.
1734+ log.warn (
1735+ 'Failed to reset dashboard checks ${checkRunEvent .checkRun !.id } to in progress' ,
1736+ e,
1737+ s,
1738+ );
1739+ }
1740+ case Config .kCiYamlCheckName:
1741+ // The CheckRunEvent.checkRun.pullRequests array is empty for this
1742+ // event, so we need to find the matching pull request.
1743+ final headSha = checkRunEvent.checkRun! .headSha! ;
1744+ final checkSuiteId = checkRunEvent.checkRun! .checkSuite! .id! ;
1745+ final pullRequest = await _githubChecksService.findMatchingPullRequest (
1746+ slug,
1747+ headSha,
1748+ checkSuiteId,
17421749 );
1750+ if (pullRequest != null ) {
1751+ log.debug ('Matched PR: ${pullRequest .number } Repo: ${slug .fullName }' );
1752+ await triggerPresubmitTargets (pullRequest: pullRequest);
1753+ success = true ;
1754+ } else {
1755+ log.warn ('No matching PR found for head_sha in check run event.' );
1756+ }
1757+ case _:
1758+ try {
1759+ final sha = checkRunEvent.checkRun! .headSha! ;
17431760
1744- // TODO(matanlurey): Refactor into its own branch.
1745- // https://github.com/flutter/flutter/issues/167211.
1746- final isPresubmit = fsCommit == null ;
1747- if (isPresubmit) {
1748- log.debug ('Rescheduling presubmit build for $name ' );
1749- final pullRequest = await PrCheckRuns .findPullRequestForSha (
1761+ // Only merged commits are added to the Database.
1762+ // If a commit is found, this must be a postsubmit checkrun.
1763+ final fsCommit = await fs.Commit .tryFromFirestoreBySha (
17501764 _firestore,
1751- sha,
1765+ sha: sha ,
17521766 );
1753- if (pullRequest == null ) {
1754- return ProcessCheckRunResult .userError (
1755- 'Asked to reschedule presubmits for unknown sha/PR: $sha ' ,
1756- );
1757- }
1758- await reRunTargets (slug, pullRequest, [name! ]);
1759- } else {
1760- log.debug ('Rescheduling postsubmit build.' );
1761-
1762- final checkName = name;
1763- final fs.Task fsTask;
17641767
1765- // Query the lastest run of the `checkName` againt commit `sha`.
1766- final fsTasks = await _firestore.queryRecentTasks (
1767- limit: 1 ,
1768- commitSha: fsCommit.sha,
1769- name: checkName,
1770- );
1771- if (fsTasks.isEmpty) {
1772- throw StateError ('Expected 1+ tasks for $checkName ' );
1768+ // TODO(matanlurey): Refactor into its own branch.
1769+ // https://github.com/flutter/flutter/issues/167211.
1770+ final isPresubmit = fsCommit == null ;
1771+ if (isPresubmit) {
1772+ log.debug ('Rescheduling presubmit build for $name ' );
1773+ final pullRequest = await PrCheckRuns .findPullRequestForSha (
1774+ _firestore,
1775+ sha,
1776+ );
1777+ if (pullRequest == null ) {
1778+ return ProcessCheckRunResult .userError (
1779+ 'Asked to reschedule presubmits for unknown sha/PR: $sha ' ,
1780+ );
1781+ }
1782+ await reRunTargets (slug, pullRequest, [name! ]);
1783+ } else {
1784+ log.debug ('Rescheduling postsubmit build.' );
1785+
1786+ final checkName = name;
1787+ final fs.Task fsTask;
1788+
1789+ // Query the lastest run of the `checkName` againt commit `sha`.
1790+ final fsTasks = await _firestore.queryRecentTasks (
1791+ limit: 1 ,
1792+ commitSha: fsCommit.sha,
1793+ name: checkName,
1794+ );
1795+ if (fsTasks.isEmpty) {
1796+ throw StateError ('Expected 1+ tasks for $checkName ' );
1797+ }
1798+ fsTask = fsTasks.first;
1799+
1800+ log.debug ('Latest firestore task is $fsTask ' );
1801+ final ciYaml = await _ciYamlFetcher.getCiYamlByCommit (
1802+ fsCommit.toRef (),
1803+ postsubmit: true ,
1804+ );
1805+ final target = ciYaml.postsubmitTargets ().singleWhere (
1806+ (target) => target.name == fsTask.taskName,
1807+ );
1808+ await _luciBuildService.reschedulePostsubmitBuildUsingCheckRunEvent (
1809+ checkRunEvent,
1810+ commit: fsCommit.toRef (),
1811+ task: fsTask,
1812+ target: target,
1813+ );
17731814 }
1774- fsTask = fsTasks.first;
17751815
1776- log.debug ('Latest firestore task is $fsTask ' );
1777- final ciYaml = await _ciYamlFetcher.getCiYamlByCommit (
1778- fsCommit.toRef (),
1779- postsubmit: true ,
1780- );
1781- final target = ciYaml.postsubmitTargets ().singleWhere (
1782- (target) => target.name == fsTask.taskName,
1783- );
1784- await _luciBuildService.reschedulePostsubmitBuildUsingCheckRunEvent (
1785- checkRunEvent,
1786- commit: fsCommit.toRef (),
1787- task: fsTask,
1788- target: target,
1789- );
1816+ success = true ;
1817+ } on NoBuildFoundException {
1818+ log.warn ('No build found to reschedule.' );
1819+ } on FormatException catch (e) {
1820+ // See https://github.com/flutter/flutter/issues/165018.
1821+ log.info ('CheckName: $name failed due to user error: $e ' );
1822+ return ProcessCheckRunResult .userError ('$e ' );
17901823 }
1791-
1792- success = true ;
1793- } on NoBuildFoundException {
1794- log.warn ('No build found to reschedule.' );
1795- } on FormatException catch (e) {
1796- // See https://github.com/flutter/flutter/issues/165018.
1797- log.info ('CheckName: $name failed due to user error: $e ' );
1798- return ProcessCheckRunResult .userError ('$e ' );
1799- }
18001824 }
18011825
18021826 log.debug ('CheckName: $name State: $success ' );
0 commit comments