diff --git a/.changeset/wild-corners-lie.md b/.changeset/wild-corners-lie.md
new file mode 100644
index 0000000..27ffd3a
--- /dev/null
+++ b/.changeset/wild-corners-lie.md
@@ -0,0 +1,5 @@
+---
+"draupnir": patch
+---
+
+Add branch information to status command output.
diff --git a/.gitignore b/.gitignore
index b5d5d8c..fb4533b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,8 +25,11 @@ venv/
/db
-# version file generated from yarn build
+# version file generated from npm build
version.txt
+# branch file generated from npm build
+branch.txt
+
# Logs
logs
*.log
diff --git a/apps/draupnir/package.json b/apps/draupnir/package.json
index a33abf5..121ec35 100644
--- a/apps/draupnir/package.json
+++ b/apps/draupnir/package.json
@@ -9,8 +9,9 @@
"private": true,
"scripts": {
"build": "tsc --project test/tsconfig.json && npm run build:assets",
- "build:assets": "cp src/protections/DraupnirNews/news.json dist/protections/DraupnirNews/news.json && npm run describe-version",
+ "build:assets": "cp src/protections/DraupnirNews/news.json dist/protections/DraupnirNews/news.json && npm run describe-version && npm run describe-branch",
"describe-version": "(git describe > version.txt.tmp && mv version.txt.tmp version.txt) || true && rm -f version.txt.tmp",
+ "describe-branch": "(git rev-parse --abbrev-ref HEAD > branch.txt.tmp && mv branch.txt.tmp branch.txt) || true && rm -f branch.txt.tmp",
"harness-registration": "node dist/appservice/cli.js -r -u \"http://host.docker.internal:9000\" --enable-source-maps",
"test:unit": "mocha --require './test/tsnode.cjs' --forbid-only 'test/unit/**/*.{ts,tsx}'",
"test:unit:single": "mocha --require test/tsnode.cjs",
diff --git a/apps/draupnir/src/commands/StatusCommand.tsx b/apps/draupnir/src/commands/StatusCommand.tsx
index 0662b25..a838c2a 100644
--- a/apps/draupnir/src/commands/StatusCommand.tsx
+++ b/apps/draupnir/src/commands/StatusCommand.tsx
@@ -8,7 +8,12 @@
// https://github.com/matrix-org/mjolnir
//
-import { DOCUMENTATION_URL, PACKAGE_JSON, SOFTWARE_VERSION } from "../config";
+import {
+ CURRENT_BRANCH,
+ DOCUMENTATION_URL,
+ PACKAGE_JSON,
+ SOFTWARE_VERSION,
+} from "../config";
import {
ActionResult,
Ok,
@@ -51,6 +56,7 @@ export type StatusInfo = {
numberOfProtectedRooms: number;
numberOfUniqueMembers: number;
version: string;
+ branch: string;
repository: string;
documentationURL: string;
} & DraupnirNotificationRoomsInfo &
@@ -135,6 +141,7 @@ export function draupnirStatusInfo(draupnir: Draupnir): StatusInfo {
subscribedButPartedLists: watchedListInfo.subscribedButPartedLists,
documentationURL: DOCUMENTATION_URL,
version: SOFTWARE_VERSION,
+ branch: CURRENT_BRANCH,
repository: (PACKAGE_JSON["repository"] as string | undefined) ?? "Unknown",
...extractProtectionNotificationRooms(draupnir),
};
@@ -231,6 +238,9 @@ export function renderStatusInfo(info: StatusInfo): DocumentNode {
Version:
{info.version}
+ Branch:
+ {info.branch}
+
Repository:
{info.repository}
diff --git a/apps/draupnir/src/config.ts b/apps/draupnir/src/config.ts
index e793908..b192929 100644
--- a/apps/draupnir/src/config.ts
+++ b/apps/draupnir/src/config.ts
@@ -471,6 +471,24 @@ export const SOFTWARE_VERSION = (() => {
return /^(.*)$/m.exec(versionFile)?.at(0) ?? defaultText;
})();
+export const CURRENT_BRANCH = (() => {
+ let branchFile;
+ const defaultText =
+ "A branch name was either not provided when building Draupnir or could not be read.";
+ try {
+ branchFile = fs.readFileSync(
+ path.join(__dirname, "../branch.txt"),
+ "utf-8"
+ );
+ } catch (e) {
+ LogService.error("config", "Could not read Draupnir branch", e);
+ branchFile = defaultText;
+ }
+ // it's important to ignore the newline if the branch is going to be put
+ // into
or where it will create an unnecessary newline.
+ return /^(.*)$/m.exec(branchFile)?.at(0) ?? defaultText;
+})();
+
export const DOCUMENTATION_URL =
"https://the-draupnir-project.github.io/draupnir-documentation/";