Coder Social home page Coder Social logo

saadbruno / perforce-discord-webhook Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 4.0 14 KB

Posts a message to Discord every time a new changelist is submitted from the Perforce version control system

License: MIT License

Shell 100.00%
perforce commit changelist change p4 p4v p4d p4-describe p4-changes discord webhook p4-triggers triggers

perforce-discord-webhook's Introduction

Perforce Discord Webhook

This is a script that posts a message to Discord every time a new changelist is submitted from the Perforce version control system.

image

Requirements:

  1. This was only tested with p4d running on a linux system (Ubuntu 18.04)
  2. The Perforce user needs access read access to the depot, so it can access the p4 describe command (more info below)
  3. You need a Discord Webhook set up
  4. You need access to edit the p4 triggers on the server

Installation:

1. Setting up p4 access on the command line

Perforce triggers run as the same linux user as the Perforce server is running. It's usually the perforce user, but you can double check by running ps aux | grep p4d

So for the script to work, the perforce user needs to be able to run p4 describe successfully. To do that, the steps are as following:

  1. Log in as the perforce user on the terminal by running sudo su perforce (followed by bash if needed).
  2. Set your Perforce login by running
p4 set P4PORT=ssl:localhost:1666
p4 set P4USER=your.username
p4 trust
p4 login

Followed by your password.

  • It's easier if the user set up in this step has no session timeout, so you don't have to log in over and over. You can change that in the p4 admin app. (See suggestion below)
  • If your server doesn't support SSL, make sure to remove ssl: from the P4PORT. Ex.: p4 set P4PORT=localhost:1666

Note on p4dctl

If you're using p4dctl to manage your servers, the user set in the p4dctl config must be the same as set on item 1.2 (in the p4 set P4USER=your.username command)

To check that, either check the /etc/perforce/p4dctl.conf file or the /etc/perforce/p4dctl.conf.d/ directory containing your server configuration file. More info here.

2. Setting up the script

That's the easy part.

  1. Clone the repo, or download the script and save it somewhere where the perforce user (or whatever user your server is running) has access to.
  2. Make sure the script is executable by running chmod u+x perforce_discord_webhook.sh

At this point, you should already be able to run the script manually with ./perforce_discord_webhook.sh <changelist number> <discord webhook link>

3. Setting up the trigger

Perforce has a Triggers system, where you can configure the server to do actions based on triggers. We are gonna create a trigger that runs this script every time a cahngelist is submitted successfully

  1. on a terminal run p4 triggers. This will open the server triggers editor.
  2. Add a new trigger with these settings:
Triggers:
	discord change-commit //depot/... "/bin/bash <perforce_discord_webhook.sh location> %changelist% <discord webhook link>

And replace the location and the webhook links according to your setup. Example:

	discord change-commit //depot/... "/bin/bash /home/perforce/perforce_discord_webhook.sh %changelist% https://discordapp.com/api/webhooks/<id>/<auth>"

You can also customize this to trigger only on specific directories by changing the //depot/... bit.

Note: It is really important to keep the tab before the trigger line, otherwise the server will not recognize it.

p4 triggers documentation
You can also run p4 help triggers for more info


At this point, everything should be working as intended! Submit a new changelist and check it out!


Suggestion: user management

In item 1.2 it was mentioned that it's easier if the user running the p4 describe command doesn't have a timeout so you don't need to reauthenticate from time to time.

For security reasons, it is better to set up a user that has only read access to the depot, and can only be used from the localhost.

  1. On the P4Admin app, create a new group with unset session time out
  2. Create a new user and assign it to that group.
  3. On the permissions tab, add the following line:
Access Level User / Group Name Host Folder / File
read user (the username you created) 127.0.0.1 //depot/...

This will mean this new user will have no session timeout, but will only be able to read the depot, and from the localhost.

perforce-discord-webhook's People

Contributors

saadbruno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

perforce-discord-webhook's Issues

"/bin/sh: 1: p4: not found"

oot@ubuntu-4gb-ash-1:/home/perforce-commit-discord-bot# python3 app.py
/bin/sh: 1: p4: not found

I'm wondering if you could help me with this?

Failed authentication check

When I run this script manually, it works perfectly and the message shows up in my Discord server. When I submit a changelist to our depot, it runs but nothing happens. When I look at the debug output file, output, desc, and user are all blank. I checked my Perforce server log and it appears to run user-describe twice. The first one completes, but the second one is followed by failed authentication check.

Can you offer any guidance on why this might be happening?

p4 trigger not doing anything but manually running script works

It works when I called it manually for change 9, but it wont work for any changes that I'm pushing.. can you help me please this is the output log:

:: Running perforce_discord_webhook.sh

:: Sending webhook...

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
^M 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0^M100 261 0 0 100 261 0 3000 --:--:-- --:--:-- --:--:-- 3000

===== DEBUG =====
:: Linux user:
root

:: Linux path:
/mnt/perforcedisk/discordwebhook

:: p4 info:
User name: ReiVieira
Client name: my_client
Client host: ghosts-perforce
Client unknown.
Current directory: /mnt/perforcedisk/discordwebhook
Peer address: 127.0.0.1:57382
Client address: 127.0.0.1
Server address: localhost:3000
Server root: /mnt/perforcedisk/perforce/root
Server date: 2022/04/03 19:08:18 +0000 UTC
Server uptime: 00:12:04
Server version: P4D/LINUX26X86_64/2021.2/2264565 (2022/03/22)
ServerID: perforce
Server services: commit-server
Server license: none
Case Handling: insensitive

:: output:
Change 9 by ReiVieira@ReiVieira_DESKTOP_GOT_Dev on 2022/04/02 12:20:29

    remove error messagse from unused anim bp

Affected files ...

... //Streams/Dev-GhostsOfTabor/GhostsOfTabor/Content/A_GhostsOfTabor/Blueprints/Character/Animation/ThirdPerson_AnimBP.uasset#2 edit

:: desc:
remove error messagse from unused anim bp

:: user:
ReiVieira@ReiVieira_DESKTOP_GOT_Dev

:: embed:
{ "username":"P4V","avatar_url":"https://i.imgur.com/unlgXvg.png","embeds":[{ "title":"Change 9 by ReiVieira@ReiVieira_DESKTOP_GOT_Dev","color":"701425","fields":[{ "name":"Description","va>
","inline":false} ]}]}

:: Arg 1:
9

:: Arg 2:
webhooklink

change-submit Trigger not working

Hey, I'm having a similar issue to the issue posted 4 months ago.

When I run the script manually, my discord webhook works and I can see a changelist update.

However when i setup the trigger via
discord change-submit //depot/... "/bin/bash /home/perforce/perforce_discord_webhook.sh %changelist% <insert webhook here>
it doesn't work.
I have verified the script directory and webhook.

One thing to note is I can't run
P4 Trust
when when my P4PORT is set to ssl:localhost:1666 it just complains saying
Perforce client error: Connect to server failed; check $P4PORT. connect: 127.0.0.1:1666: Connection refused
But when i set my P4PORT to my public IP it works fine.

I'm suspecting this has something to do with my Trigger not firing properly.
I was wondering if you had any pointers to how I should fix this.
Thanks!

Perforce password (P4PASSWD) invalid or unset :<

Hello! I've been trying to get this to work, even though I have noooo idea what I'm doing when it comes to these kinds of setups.
I figured I'd ask for help, I've looked through the other 2 issues that has been resolved but I can't verify my issues the same way as they did as I don't have a "p4dctl.conf.d/master.conf" (guessing since I'm not running p4dctl to run my servers?)

I think I've set up the trigger correctly as I see it with the p4 logging options in p4v, but the main issue I have is that I'm getting
"Perforce password (P4PASSWD) invalid or unset", which I'm guessing is the root of the issue.

If I run the " ./perforce_discord_webhook.sh x x"-command it sends the msg to discord :S

Any advice in how I can debug this thing? Been trying for a couple of days now to get it working but no luck:D
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.