|
| 1 | +<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 | +<!DOCTYPE muclient> |
| 3 | + |
| 4 | +<muclient> |
| 5 | +<plugin |
| 6 | + name="Make_Announcement" |
| 7 | + author="Nick Gammon" |
| 8 | + id="0aab03f457948d2a21141b50" |
| 9 | + language="Lua" |
| 10 | + purpose="Makes the announcement for a new version of MUSHclient" |
| 11 | + date_written="2010-11-15" |
| 12 | + requires="4.60" |
| 13 | + version="1" |
| 14 | + > |
| 15 | +<description trim="y"> |
| 16 | +<![CDATA[ |
| 17 | +
|
| 18 | +Type: make_announcement |
| 19 | +
|
| 20 | +]]> |
| 21 | +</description> |
| 22 | + |
| 23 | +</plugin> |
| 24 | + |
| 25 | +<!-- Aliases --> |
| 26 | + |
| 27 | +<aliases> |
| 28 | + <alias |
| 29 | + name="make_announcement" |
| 30 | + script="make_announcement" |
| 31 | + match="make_announcement" |
| 32 | + enabled="y" |
| 33 | + sequence="100" |
| 34 | + > |
| 35 | + </alias> |
| 36 | +</aliases> |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +<!-- Script --> |
| 42 | + |
| 43 | + |
| 44 | +<script> |
| 45 | +<![CDATA[ |
| 46 | +
|
| 47 | +VERSION_URL = "http://www.mushclient.com/scripts/version.php" |
| 48 | +
|
| 49 | +SOURCE = "c:\\source\\mushclient\\install\\" |
| 50 | +
|
| 51 | +TEMPLATE = "announcement_template.txt" |
| 52 | +GIT_DIFF_FILE = "git_diff_output.txt" |
| 53 | +GIT_LOG_FILE = "git_log_output.txt" |
| 54 | +
|
| 55 | +GIT_HUB = "http://github.com/nickgammon/mushclient" |
| 56 | +
|
| 57 | +function make_announcement () |
| 58 | + |
| 59 | + |
| 60 | + -- grab updated MUSHclient info from web site |
| 61 | + local http = require "socket.http" |
| 62 | + |
| 63 | + SetStatus "Checking for latest MUSHclient version ..." |
| 64 | + local page = http.request (VERSION_URL) |
| 65 | + SetStatus "Ready" |
| 66 | + |
| 67 | + if not page then return end -- page doesn't exist |
| 68 | + |
| 69 | + local s = string.match (page, "<pre>(.*)</pre>") |
| 70 | + |
| 71 | + if not s then return end -- page in wrong format |
| 72 | + |
| 73 | + local t = {} |
| 74 | + setfenv (assert (loadstring (s)), t) () -- compile and load into t |
| 75 | + |
| 76 | + info = t.installer_info |
| 77 | + |
| 78 | + if not info then return end -- installer_info not there |
| 79 | + |
| 80 | + -- grab version number and other stuff from that page |
| 81 | + |
| 82 | + new_version = tonumber (info.version) |
| 83 | + previous_version = string.format ("%0.2f", new_version - 0.01) |
| 84 | + installer_size = string.format ("%0.2f", info.installer_size / 1024 / 1024) |
| 85 | + installer_file = string.match (info.installer_url, "[%w_.]+$") |
| 86 | + description = string.gsub ("\n" .. FixupHTML (info.description), "\n%*", "<li>") |
| 87 | + |
| 88 | + -- remove any old interim files |
| 89 | + os.remove (SOURCE .. GIT_DIFF_FILE) |
| 90 | + os.remove (SOURCE .. GIT_LOG_FILE) |
| 91 | + |
| 92 | + -- do the git diff for this version and the previous one |
| 93 | + assert (utils.shellexecute ("git", |
| 94 | + string.format ("--no-pager diff v%s..v%s --stat > " |
| 95 | + .. GIT_DIFF_FILE, |
| 96 | + previous_version, info.version), |
| 97 | + SOURCE)) |
| 98 | + |
| 99 | + -- do the git log for this version and the previous one |
| 100 | + assert (utils.shellexecute ("git", |
| 101 | + string.format ("--no-pager log --pretty=oneline --reverse --abbrev-commit v%s..v%s > " |
| 102 | + .. GIT_LOG_FILE, |
| 103 | + previous_version, info.version), |
| 104 | + SOURCE)) |
| 105 | +
|
| 106 | + -- give them time to finish |
| 107 | + utils.msgbox "press <OK> when DOS windows closed" |
| 108 | + |
| 109 | + -- get template of announcement |
| 110 | + local f = assert (io.open (SOURCE .. TEMPLATE, "r")) |
| 111 | + local template = f:read ("*a") |
| 112 | + f:close () |
| 113 | + |
| 114 | + -- get git diff |
| 115 | + local f = assert (io.open (SOURCE .. GIT_DIFF_FILE, "r")) |
| 116 | + local git_diff = FixupHTML (f:read ("*a")) |
| 117 | + f:close () |
| 118 | +
|
| 119 | + -- get git log |
| 120 | + local f = assert (io.open (SOURCE .. GIT_LOG_FILE, "r")) |
| 121 | + local git_raw_log = f:read ("*a") |
| 122 | + f:close () |
| 123 | + |
| 124 | + -- fix up log to have hyperlinks |
| 125 | + local t = {} |
| 126 | + |
| 127 | + for commit_code, desc in string.gmatch (git_raw_log, "(%x+) ([^\n]+)") do |
| 128 | + table.insert (t, string.format ( |
| 129 | + '<a href="%s/commit/%s">%s</a> %s', |
| 130 | + GIT_HUB, |
| 131 | + commit_code, |
| 132 | + commit_code, |
| 133 | + FixupHTML (desc))) |
| 134 | + end -- for |
| 135 | + |
| 136 | + local git_log = table.concat (t, "\n") |
| 137 | + |
| 138 | + -- table of replacements |
| 139 | + replacements = { |
| 140 | + |
| 141 | + ["<<version>>"] = info.version, |
| 142 | + ["<<previous_version>>"] = previous_version, |
| 143 | + ["<<installer_hash>>"] = info.installer_hash, |
| 144 | + ["<<installer_size>>"] = installer_size, |
| 145 | + ["<<installer_url>>"] = info.installer_url, |
| 146 | + ["<<installer_file>>"] = installer_file, |
| 147 | + ["<<description>>"] = description, |
| 148 | + ["<<git_diff>>"] = git_diff, |
| 149 | + ["<<git_log>>"] = git_log, |
| 150 | + |
| 151 | + } -- end of replacements |
| 152 | + |
| 153 | + -- do the replacements |
| 154 | + template = string.gsub (template, "<<[%w_]+>>", replacements) |
| 155 | +
|
| 156 | + -- output to MUSHclient window for checking |
| 157 | + print (string.rep ("-", 80)) |
| 158 | + ColourNote ("cyan", "", template) |
| 159 | + print (string.rep ("-", 80)) |
| 160 | +
|
| 161 | + -- fix up newlines |
| 162 | + template = string.gsub (template, "\r", "") |
| 163 | + template = string.gsub (template, "\n", "\r\n") |
| 164 | + |
| 165 | + -- put onto clipboard |
| 166 | + SetClipboard (template) |
| 167 | + ColourNote ("green", "", "(Copied to clipboard)") |
| 168 | + |
| 169 | +end -- make_announcement |
| 170 | +
|
| 171 | +
|
| 172 | +ColourNote ("cyan", "", "Type: make_announcement") |
| 173 | +
|
| 174 | +]]> |
| 175 | +</script> |
| 176 | + |
| 177 | +</muclient> |
0 commit comments