diff --git a/Js script to interprete json from gitea to channel.js b/Js script to interprete json from gitea to channel.js new file mode 100644 index 0000000..66d9364 --- /dev/null +++ b/Js script to interprete json from gitea to channel.js @@ -0,0 +1,244 @@ +/* exported Script */ + +String.prototype.capitalizeFirstLetter = function() { + return this.charAt(0).toUpperCase() + this.slice(1); +} + +const getLabelsField = (labels) => { + let labelsArray = []; + labels.forEach(function(label) { + labelsArray.push(label.name); + }); + labelsArray = labelsArray.join(', '); + return { + title: 'Labels', + value: labelsArray, + short: labelsArray.length <= 40 + }; +}; + +const githubEvents = { + ping(request) { + return { + content: { + text: '_' + request.content.hook.id + '_\n' + ':thumbsup: ' + request.content.zen + } + }; + }, + + /* NEW OR MODIFY ISSUE */ + issues(request) { + const user = request.content.sender; + + if (request.content.action == "opened" || request.content.action == "reopened" || request.content.action == "edited") { + var body = request.content.issue.body; + } else if (request.content.action == "labeled") { + var body = "Current labels: " + getLabelsField(request.content.issue.labels).value; + } else if (request.content.action == "assigned" || request.content.action == "unassigned") { + // Note that the issues API only gives you one assignee. + var body = "Current assignee: " + request.content.issue.assignee.login; + } else if (request.content.action == "closed") { + if (request.content.issue.closed_by) { + var body = "Closed by: " + request.content.issue.closed_by.login; + } else { + var body = "Closed."; + } + } else { + return { + error: { + success: false, + message: 'Unsupported issue action' + } + }; + } + + const action = request.content.action.capitalizeFirstLetter(); + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' issue ​#' + request.content.issue.number + + ' - ' + request.content.issue.title + '](' + + request.content.issue.html_url + ')**\n\n' + + body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + + /* COMMENT ON EXISTING ISSUE */ + issue_comment(request) { + const user = request.content.comment.user; + + if (request.content.action == "edited") { + var action = "Edited comment "; + } else { + var action = "Comment " + } + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' on issue ​#' + request.content.issue.number + + ' - ' + request.content.issue.title + '](' + + request.content.comment.html_url + ')**\n\n' + + request.content.comment.body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + + /* COMMENT ON COMMIT */ +commit_comment(request) { + const user = request.content.comment.user; + + if (request.content.action == "edited") { + var action = "Edited comment "; + } else { + var action = "Comment " + } + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' on commit id ' + request.content.comment.commit_id + + ' - ' + + '](' + + request.content.comment.html_url + ')**\n\n' + + request.content.comment.body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + /* END OF COMMENT ON COMMIT */ + + /* PUSH TO REPO */ + push(request) { + var commits = request.content.commits; + var multi_commit = "" + var is_short = true; + var changeset = 'Changeset'; + if ( commits.length > 1 ) { + var multi_commit = " [Multiple Commits]"; + var is_short = false; + var changeset = changeset + 's'; + var output = []; + } + const user = request.content.sender; + + var text = '**Pushed to ' + "["+request.content.repository.full_name+"]("+request.content.repository.url+"):" + + request.content.ref.split('/').pop() + "**\n\n"; + + for (var i = 0; i < commits.length; i++) { + var commit = commits[i]; + var shortID = commit.id.substring(0,7); + var a = '[' + shortID + '](' + commit.url + ') - ' + commit.message; + if ( commits.length > 1 ) { + output.push( a ); + } else { + var output = a; + } + } + + if (commits.length > 1) { + text += output.reverse().join('\n'); + } else { + text += output; + } + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, // End GitHub Push + + /* NEW PULL REQUEST */ + pull_request(request) { + const user = request.content.sender; + + if (request.content.action == "opened" || request.content.action == "reopened" || request.content.action == "edited" || request.content.action == "synchronize") { + var body = request.content.pull_request.body; + } else if (request.content.action == "labeled") { + var body = "Current labels: " + getLabelsField(request.content.pull_request.labels).value; + } else if (request.content.action == "assigned" || request.content.action == "unassigned") { + // Note that the issues API only gives you one assignee. + var body = "Current assignee: " + request.content.pull_request.assignee.login; + } else if (request.content.action == "closed") { + if (request.content.pull_request.merged) { + var body = "Merged by: " + request.content.pull_request.merged_by.login; + } else { + var body = "Closed."; + } + } else { + return { + error: { + success: false, + message: 'Unsupported pull request action' + } + }; + } + + const action = request.content.action.capitalizeFirstLetter(); + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' pull request ​#' + request.content.pull_request.number + + ' - ' + request.content.pull_request.title + '](' + + request.content.pull_request.html_url + ')**\n\n' + + body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, +}; + +class Script { + process_incoming_request({ request }) { + const header = request.headers['x-github-event']; + if (githubEvents[header]) { + return githubEvents[header](request); + } + + return { + error: { + success: false, + message: 'Unsupported method' + } + }; + } +} diff --git a/bugzilla rss to rocket json.py b/bugzilla rss to rocket json.py new file mode 100644 index 0000000..98fcbed --- /dev/null +++ b/bugzilla rss to rocket json.py @@ -0,0 +1,55 @@ +import time +import feedparser +import requests + +# Bugzilla RSS feed URL +BUGZILLA_RSS_URL = "https://bugs.koozali.org/buglist.cgi?chfield=%5BBug%20creation%5D&chfieldfrom=7d&ctype=atom&title=Bugs%20reported%20in%20the%20last%207%20days" +# Updated Rocket.Chat webhook URL +ROCKET_CHAT_URL = "https://chat.koozali.org/hooks/677e97a73ddf8049989dbc8c/r9uiYpTRAXo3mkFKxHnoTwGCdtKpYaDemCpHArgz89knkwLo" + +# Set to keep track of sent bug IDs +sent_bugs = set() + +# Function to send message to Rocket.Chat +def send_to_rocket_chat(bug_title, bug_link, bug_id): + payload = { + "alias": "Bugzilla", + "text": f"Bug Report - ID: {bug_id}", + "attachments": [ + { + "title": bug_title, + "title_link": bug_link, + "color": "#764FA5" + } + ] + } + response = requests.post(ROCKET_CHAT_URL, json=payload) + if response.status_code == 200: + print(f"Bug report sent successfully: {bug_title} (ID: {bug_id})") + else: + print(f"Failed to send bug report: {response.status_code} - {response.text}") + +# Function to fetch and parse the Bugzilla RSS feed +def fetch_bugzilla_feed(): + feed = feedparser.parse(BUGZILLA_RSS_URL) + return feed.entries + +# Main polling loop +def main(): + while True: + entries = fetch_bugzilla_feed() + + for entry in entries: + bug_id = entry.id.split('=')[-1] # Extract the bug number from the URL + if bug_id not in sent_bugs: + title = entry.title.strip() + link = entry.link + # Send the bug title, link, and ID + send_to_rocket_chat(title, link, bug_id) + sent_bugs.add(bug_id) # Track the sent bug ID + + # Wait for 1 minute before polling again + time.sleep(60) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/koji rss to rocket json.py b/koji rss to rocket json.py new file mode 100644 index 0000000..44c6e28 --- /dev/null +++ b/koji rss to rocket json.py @@ -0,0 +1,57 @@ +import time +import feedparser +import requests + +# Koji RSS feed URL +KOJI_RSS_URL = "http://koji.koozali.org/koji/recentbuilds?feed=rss" +# Rocket.Chat webhook URL +ROCKET_CHAT_URL = "https://chat.koozali.org/hooks/66d24441effca216c2ca309f/KJLaNwc5vyHwqz5MhRDpBkKWnQuAfsCX3xZMHxPhpuqmFgBn" + +# Function to send message to Rocket.Chat +def send_to_rocket_chat(message_title, message_link, message_description): + payload = { + "alias": "Koji", + "text": message_title, + "attachments": [ + { + "title": message_title, + "title_link": message_link, + "text": message_description, +# "image_url": "https://chat.koozali.org/images/integration-attachment-example.png", + "color": "#764FA5" + } + ] + } + response = requests.post(ROCKET_CHAT_URL, json=payload) + if response.status_code == 200: + print(f"Message ({title}) sent successfully!") + else: + print(f"Failed to send message: {response.status_code} - {response.text}") + +# Function to fetch and parse the Koji RSS feed +def fetch_koji_feed(): + feed = feedparser.parse(KOJI_RSS_URL) + if feed.entries: + latest_build = feed.entries[0] + title = latest_build.title.strip() + link = latest_build.link + description = latest_build.description.strip().replace("
", "").replace("
", "") + return title, link, description + return None, None, None + +# Main polling loop +def main(): + last_title = None + + while True: + title, link, description = fetch_koji_feed() + + if title and title != last_title: + send_to_rocket_chat(title, link, description) + last_title = title + + # Wait for 1 minute before polling again + time.sleep(60) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/modified Js script to interprete json from gitea to channel.js b/modified Js script to interprete json from gitea to channel.js new file mode 100644 index 0000000..eb65022 --- /dev/null +++ b/modified Js script to interprete json from gitea to channel.js @@ -0,0 +1,250 @@ +/* exported Script */ + +String.prototype.capitalizeFirstLetter = function() { + return this.charAt(0).toUpperCase() + this.slice(1); +} + +const getLabelsField = (labels) => { + let labelsArray = []; + labels.forEach(function(label) { + labelsArray.push(label.name); + }); + labelsArray = labelsArray.join(', '); + return { + title: 'Labels', + value: labelsArray, + short: labelsArray.length <= 40 + }; +}; + +const githubEvents = { + ping(request) { + return { + content: { + text: '_' + request.content.hook.id + '_\n' + ':thumbsup: ' + request.content.zen + } + }; + }, + + /* NEW OR MODIFY ISSUE */ + issues(request) { + const user = request.content.sender; + + if (request.content.action == "opened" || request.content.action == "reopened" || request.content.action == "edited") { + var body = request.content.issue.body; + } else if (request.content.action == "labeled") { + var body = "Current labels: " + getLabelsField(request.content.issue.labels).value; + } else if (request.content.action == "assigned" || request.content.action == "unassigned") { + // Note that the issues API only gives you one assignee. + var body = "Current assignee: " + request.content.issue.assignee.login; + } else if (request.content.action == "closed") { + if (request.content.issue.closed_by) { + var body = "Closed by: " + request.content.issue.closed_by.login; + } else { + var body = "Closed."; + } + } else { + return { + error: { + success: false, + message: 'Unsupported issue action' + } + }; + } + + const action = request.content.action.capitalizeFirstLetter(); + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' issue ​#' + request.content.issue.number + + ' - ' + request.content.issue.title + '](' + + request.content.issue.html_url + ')**\n\n' + + body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + + /* COMMENT ON EXISTING ISSUE */ + issue_comment(request) { + const user = request.content.comment.user; + + if (request.content.action == "edited") { + var action = "Edited comment "; + } else { + var action = "Comment " + } + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' on issue ​#' + request.content.issue.number + + ' - ' + request.content.issue.title + '](' + + request.content.comment.html_url + ')**\n\n' + + request.content.comment.body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + + /* COMMENT ON COMMIT */ +commit_comment(request) { + const user = request.content.comment.user; + + if (request.content.action == "edited") { + var action = "Edited comment "; + } else { + var action = "Comment " + } + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' on commit id ' + request.content.comment.commit_id + + ' - ' + + '](' + + request.content.comment.html_url + ')**\n\n' + + request.content.comment.body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, + /* END OF COMMENT ON COMMIT */ + + /* PUSH TO REPO */ + push(request) { + // Check if the commits array is empty + var commits = request.content.commits; + + // If commits is empty, use head_commit details + if (commits.length === 0 && request.content.head_commit) { + commits = [request.content.head_commit]; // Wrap head_commit in an array for uniform processing + } + + var multi_commit = ""; + var is_short = true; + var changeset = 'Changeset'; + + if (commits.length > 1) { + multi_commit = " [Multiple Commits]"; + is_short = false; + changeset += 's'; + var output = []; + } + + const user = request.content.sender; + + var text = '**Pushed to ' + "[" + request.content.repository.full_name + "](" + request.content.repository.url + "):" + + request.content.ref.split('/').pop() + "**\n\n"; + + for (var i = 0; i < commits.length; i++) { + var commit = commits[i]; + var shortID = commit.id.substring(0, 7); + var a = '[' + shortID + '](' + commit.url + ') - ' + commit.message; + if (commits.length > 1) { + output.push(a); + } else { + output = a; // Ensure output is properly defined + } + } + + if (commits.length > 1) { + text += output.reverse().join('\n'); + } else { + text += output; + } + + return { + content: { + attachments: [{ + thumb_url: user.avatar_url, + text: text, + fields: [] + }] + } + }; +}, // End GitHub Push + /* NEW PULL REQUEST */ + pull_request(request) { + const user = request.content.sender; + + if (request.content.action == "opened" || request.content.action == "reopened" || request.content.action == "edited" || request.content.action == "synchronize") { + var body = request.content.pull_request.body; + } else if (request.content.action == "labeled") { + var body = "Current labels: " + getLabelsField(request.content.pull_request.labels).value; + } else if (request.content.action == "assigned" || request.content.action == "unassigned") { + // Note that the issues API only gives you one assignee. + var body = "Current assignee: " + request.content.pull_request.assignee.login; + } else if (request.content.action == "closed") { + if (request.content.pull_request.merged) { + var body = "Merged by: " + request.content.pull_request.merged_by.login; + } else { + var body = "Closed."; + } + } else { + return { + error: { + success: false, + message: 'Unsupported pull request action' + } + }; + } + + const action = request.content.action.capitalizeFirstLetter(); + + const text = '_' + request.content.repository.full_name + '_\n' + + '**[' + action + ' pull request ​#' + request.content.pull_request.number + + ' - ' + request.content.pull_request.title + '](' + + request.content.pull_request.html_url + ')**\n\n' + + body; + + return { + content: { + attachments: [ + { + thumb_url: user.avatar_url, + text: text, + fields: [] + } + ] + } + }; + }, +}; + +class Script { + process_incoming_request({ request }) { + const header = request.headers['x-github-event']; + if (githubEvents[header]) { + return githubEvents[header](request); + } + + return { + error: { + success: false, + message: 'Unsupported method' + } + }; + } +}