Skip to content

Commit

Permalink
Detect a new update release in git history and post to ratchat
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperManifolds committed Apr 21, 2021
1 parent f7475e4 commit 4706a4c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
43 changes: 43 additions & 0 deletions Sources/mechasqueak/Utilities/Shell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2021 The Fuel Rats Mischief

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import Foundation

func shell (_ launchPath: String, _ arguments: [String], currentDirectory: URL? = nil) -> String? {
let task = Process()
task.launchPath = launchPath
if let curDir = currentDirectory {
task.currentDirectoryURL = curDir
}
task.arguments = arguments

let pipe = Pipe()
task.standardOutput = pipe
task.launch()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: String.Encoding.utf8)

return output
}
8 changes: 6 additions & 2 deletions Sources/mechasqueak/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ class MechaSqueak {
&& userJoin.channel.name.lowercased() == configuration.general.reportingChannel.lowercased() {
mecha.reportingChannel = userJoin.channel
mecha.rescueBoard.syncBoard()
if CommandLine.arguments.count > 2 {
mecha.reportingChannel?.send(message: "Update complete. Changes available here: \(CommandLine.arguments[2])")

if let gitDir = configuration.documentationPath {
let release = shell("/usr/bin/git", ["tag", "--points-at", "HEAD"], currentDirectory: gitDir)?.trimmingCharacters(in: .whitespacesAndNewlines)
if let releaseName = release, releaseName.count > 0 {
mecha.reportingChannel?.send(message: "Update complete. Go here to read the latest changes: https://github.com/FuelRats/SwiftSqueak/releases/tag/\(releaseName)")
}
}
} else {
accounts.lookup(user: userJoin.user)
Expand Down

0 comments on commit 4706a4c

Please sign in to comment.