tdesktop/.github/workflows/issue_closer.yml

114 lines
3.4 KiB
YAML

name: Issue closer.
on:
issues:
types: opened
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Get the latest version.
run: |
tag=$(git ls-remote --tags git://github.com/$GITHUB_REPOSITORY | cut -f 2 | tail -n1)
echo $tag
echo ::set-env name=LATEST_TAG::$tag
- name: Check a version from an issue.
uses: actions/github-script@0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let errorStr = "Version not found.";
function maxIndexOf(str, i) {
let index = str.indexOf(i);
return (index == -1) ? Number.MAX_SAFE_INTEGER : index;
}
let item1 = "Version of Telegram Desktop";
let item2 = "Installation source";
let item3 = "Used theme";
let item4 = "<details>";
let body = context.payload.issue.body;
console.log("Body of issue:\n" + body);
let index1 = body.indexOf(item1);
let index2 = Math.min(
Math.min(
maxIndexOf(body, item2),
maxIndexOf(body, item3)),
maxIndexOf(body, item4));
console.log("Index 1: " + index1);
console.log("Index 2: " + index2);
if (index1 == -1) {
console.log(errorStr);
return;
}
function parseVersion(str) {
let pattern = /[0-9]\.[0-9][0-9.]{0,}/g;
return str.match(pattern);
}
function firstNum(version) {
return version[0].split(".")[0];
}
let issueVer = parseVersion(body.substring(index1 + item1.length, index2));
if (issueVer == undefined) {
console.log(errorStr);
return;
}
console.log("Version from issue: " + issueVer[0]);
let latestVer = parseVersion(process.env.LATEST_TAG);
if (latestVer == undefined) {
console.log(errorStr);
return;
}
console.log("Version from tags: " + latestVer[0]);
let issueNum = firstNum(issueVer);
let latestNum = firstNum(latestVer);
if (issueNum <= latestNum && issueNum < 5) {
console.log("Seems the version of this issue is fine!");
return;
}
let message = `
Sorry, but according to the version you specify in this issue, \
you are using the [Telegram for macOS](https://macos.telegram.org), \
not the [Telegram Desktop](https://desktop.telegram.org).
You can report your issue to [the group](https://t.me/macswift) \
or to [the repository of Telegram for macOS](https://github.com/overtake/TelegramSwift).
If I made a mistake and closed your issue wrongly, please reopen it. Thanks!
`;
let params = {
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: context.issue.number
};
github.issues.createComment({
...params,
body: message
});
github.issues.addLabels({
...params,
labels: ['TG macOS Swift']
});
github.issues.update({
...params,
state: 'closed'
});