mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Owner] Enhanced [p]version
Implemented part of #561's changes Handles non-git installations and non-default remotes Links to branch Chained commands for better peformances (theorically)
This commit is contained in:
parent
eb67e83d64
commit
dad6929843
@ -843,24 +843,37 @@ class Owner:
|
|||||||
self.setowner_lock = False
|
self.setowner_lock = False
|
||||||
|
|
||||||
def _get_version(self):
|
def _get_version(self):
|
||||||
url = os.popen(r'git config --get remote.origin.url')
|
if not os.path.isdir(".git"):
|
||||||
url = url.read().strip()[:-4]
|
msg = "This instance of Red hasn't been installed with git."
|
||||||
repo_name = url.split("/")[-1]
|
e = discord.Embed(title=msg,
|
||||||
commits = os.popen(r'git show -s -n 3 HEAD --format="%cr|%s|%H"')
|
colour=discord.Colour.red())
|
||||||
ncommits = os.popen(r'git rev-list --count HEAD').read()
|
return e
|
||||||
|
|
||||||
|
commands = " && ".join((
|
||||||
|
r'git config --get remote.origin.url', # Remote URL
|
||||||
|
r'git rev-list --count HEAD', # Number of commits
|
||||||
|
r'git rev-parse --abbrev-ref HEAD', # Branch name
|
||||||
|
r'git show -s -n 3 HEAD --format="%cr|%s|%H"' # Last 3 commits
|
||||||
|
))
|
||||||
|
result = os.popen(commands).read()
|
||||||
|
url, ncommits, branch, commits = result.split("\n", 3)
|
||||||
|
if url.endswith(".git"):
|
||||||
|
url = url[:-4]
|
||||||
|
repo_name = url.split("/")[-1]
|
||||||
|
|
||||||
lines = commits.read().split('\n')
|
|
||||||
embed = discord.Embed(title="Updates of " + repo_name,
|
embed = discord.Embed(title="Updates of " + repo_name,
|
||||||
description="Last three updates",
|
description="Last three updates",
|
||||||
colour=discord.Colour.red(),
|
colour=discord.Colour.red(),
|
||||||
url=url)
|
url="{}/tree/{}".format(url, branch))
|
||||||
for line in lines:
|
|
||||||
|
for line in commits.split('\n'):
|
||||||
if not line:
|
if not line:
|
||||||
continue
|
continue
|
||||||
when, commit, chash = line.split("|")
|
when, commit, chash = line.split("|")
|
||||||
commit_url = url + "/commit/" + chash
|
commit_url = url + "/commit/" + chash
|
||||||
content = "[{}]({}) - {} ".format(chash[:6], commit_url, commit)
|
content = "[{}]({}) - {} ".format(chash[:6], commit_url, commit)
|
||||||
embed.add_field(name=when, value=content, inline=False)
|
embed.add_field(name=when, value=content, inline=False)
|
||||||
|
|
||||||
embed.set_footer(text="Total commits: " + ncommits)
|
embed.set_footer(text="Total commits: " + ncommits)
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user