| 99 | } |
| 100 | |
| 101 | QString reprocessCommits(QByteArray json) |
| 102 | { |
| 103 | auto channel = APPLICATION->settings()->get("UpdateChannel").toString(); |
| 104 | try |
| 105 | { |
| 106 | QString result; |
| 107 | auto document = Json::requireDocument(json); |
| 108 | auto rootobject = Json::requireObject(document); |
| 109 | auto status = Json::requireString(rootobject, "status"); |
| 110 | auto diff_url = Json::requireString(rootobject, "html_url"); |
| 111 | |
| 112 | auto print_commits = [&]() |
| 113 | { |
| 114 | result += "<table cellspacing=0 cellpadding=2 style='border-width: 1px; border-style: solid'>"; |
| 115 | auto commitarray = Json::requireArray(rootobject, "commits"); |
| 116 | for(int i = commitarray.size() - 1; i >= 0; i--) |
| 117 | { |
| 118 | const auto & commitval = commitarray[i]; |
| 119 | auto commitobj = Json::requireObject(commitval); |
| 120 | auto parents_info = Json::ensureArray(commitobj, "parents"); |
| 121 | // NOTE: this ignores merge commits, because they have more than one parent |
| 122 | if(parents_info.size() > 1) |
| 123 | { |
| 124 | continue; |
| 125 | } |
| 126 | auto commit_url = Json::requireString(commitobj, "html_url"); |
| 127 | auto commit_info = Json::requireObject(commitobj, "commit"); |
| 128 | auto commit_message = Json::requireString(commit_info, "message"); |
| 129 | auto lines = commit_message.split('\n'); |
| 130 | QRegularExpression regexp("(?<prefix>(GH-(?<issuenr>[0-9]+))|(NOISSUE)|(SCRATCH))? *(?<rest>.*) *"); |
| 131 | auto match = regexp.match(lines.takeFirst(), 0, QRegularExpression::NormalMatch); |
| 132 | auto issuenr = match.captured("issuenr"); |
| 133 | auto prefix = match.captured("prefix"); |
| 134 | auto rest = match.captured("rest"); |
| 135 | result += "<tr><td>"; |
| 136 | if(issuenr.length()) |
| 137 | { |
| 138 | result += QString("<a href=\"https://github.com/PolyMC/PolyMC/issues/%1\">GH-%2</a>").arg(issuenr, issuenr); |
| 139 | } |
| 140 | else if(prefix.length()) |
| 141 | { |
| 142 | result += QString("<a href=\"%1\">%2</a>").arg(commit_url, prefix); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | result += QString("<a href=\"%1\">NOISSUE</a>").arg(commit_url); |
| 147 | } |
| 148 | result += "</td>"; |
| 149 | lines.prepend(rest); |
| 150 | result += "<td><p>" + lines.join("<br />") + "</p></td></tr>"; |
| 151 | } |
| 152 | result += "</table>"; |
| 153 | }; |
| 154 | |
| 155 | if(status == "identical") |
| 156 | { |
| 157 | return QObject::tr("<p>There are no code changes between your current version and latest %1.</p>").arg(channel); |
| 158 | } |
no test coverage detected