go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.87k stars 5.47k forks source link

Allow to specify a different URL base for Discord hook #11124

Open luwol03 opened 4 years ago

luwol03 commented 4 years ago

Description

problem

When I try to use a discord webhook, I always get a status code 400 with the body {"embeds": ["0"]}. Then I tried to analyze what this is due to.

problem solving approach

I discussed this on the gitea discord server with @6543#1089. https://discordapp.com/channels/322538954119184384/357627248095789056/700457572599201855 then I asked @6543#1089 to try it on him, which worked fine, and send me the result. So header and body. Then I started to compare the two and found out that they only differ in ID and author/repo data. Then I made the requests manually with curl. His header with my body did not work. But my header with his body. So I compared the body and changed one line until I found the culprit, or three! Discord has a problem with hostnames. I had configured my gitea instance in app.ini to use hostnames. @6543#1089 on the other hand, specified the IP. So it worked for him. So I just entered something different in the three fields (embeds[0].url; embeds[0].author.url and embeds[0].author.icon_url) and tested it with curl, and see how it works.

solution

So my idea would be, where you can enter the webhook url the username and the avatar url, just add three more fields for embeds[0].url; embeds[0].author.url and embeds[0].author.icon_url? So, that you can manually assign an url, an author url and author icon url, e.g. with a placeholder where the default values are already included.

6543 commented 4 years ago

If we could figure it out if discord can resolve gitea's hostname and use ip or hostname based on this dessision it would not add more complexity or a simple option to "Ignore Hostname" witch would result in an embeds object with empty url fields?

luwol03 commented 4 years ago

This is also an option, but I think if you can assign it individually, you can use e.g. pictures that you have uploaded on the internet.

guillep2k commented 4 years ago

Sorry, where is this IP/hostname field located? Can you post an example request made with curl? (or two)

luwol03 commented 4 years ago

In my gitea instance the ROOT_URL in app.ini is set to the hostname. For discord this is probably a problem! This is the body that does not work:

{
  "wait": false,
  "content": "",
  "username": "Gitea",
  "avatar_url": "https://s.gitea.com/img/favicon.png",
  "tts": false,
  "embeds": [
    {
      "title": "[username/Test:master] 1 new commit",
      "description": "[2a3866e](https://myhostname:3000/username/Test/commit/2a3866e1b19805c2e24637d7452158aa995e0ecd) added random stuff",
      "url": "https://myhostname:3000/username/Test/commit/2a3866e1b19805c2e24637d7452158aa995e0ecd",
      "color": 1754624,
      "footer": {
        "text": ""
      },
      "author": {
        "name": "username",
        "url": "https://myhostname:3000/username",
        "icon_url": "https://myhostname:3000/user/avatar/username/-1"
      },
      "fields": null
    }
  ]
}

because I get a 400 status code with the body

{"embeds": ["0"]}

back! But if I change the hostnames to some other reachable dns names or ip addresses:

{
  "wait": false,
  "content": "",
  "username": "Gitea",
  "avatar_url": "https://s.gitea.com/img/favicon.png",
  "tts": false,
  "embeds": [
    {
      "title": "[username/Test:master] 1 new commit",
      "description": "[2a3866e](https://myhostname:3000/username/Test/commit/2a3866e1b19805c2e24637d7452158aa995e0ecd) added random stuff",
      "url": "https://gitea.com", ## This line
      "color": 1754624,
      "footer": {
        "text": ""
      },
      "author": {
        "name": "username",
        "url": "https://gitea.io",  ## This line
        "icon_url": "https://img.icons8.com/pastel-glyph/2x/worldwide-location.png" ## This line
      },
      "fields": null
    }
  ]
}

I get back a 204 status code! And my idea would be, that you put one extra fields and one checkbox on the page, where you create webhook at gitea. Because then you can upload your own pictures on the internet and use them in discord! Here is an example of me! image I hope that's made it clearer.

guillep2k commented 4 years ago

Much clear! Thanks.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

luwol03 commented 4 years ago

It's applicable!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

6543 commented 4 years ago

Ping