-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
955af6e
commit 5957bbf
Showing
16 changed files
with
233 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/usr/bin/python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
home = /usr/bin | ||
include-system-site-packages = false | ||
version = 3.12.3 | ||
executable = /usr/bin/python3.12 | ||
command = /usr/bin/python3 -m venv /home/dhruv-sharma/Desktop/OWASP_BLT/BLT/myenv |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import requests | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
|
||
from website.models import Project # Replace `website` with the actual app name | ||
|
||
SLACK_TOKEN = settings.SLACK_TOKEN | ||
SLACK_API_URL = "https://slack.com/api/conversations.list" | ||
HEADERS = {"Authorization": f"Bearer {SLACK_TOKEN}"} | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Fetch Slack channels and associate them with projects" | ||
|
||
def fetch_channels(self): | ||
url = SLACK_API_URL | ||
params = {"limit": 1000, "types": "public_channel"} # Fetch only public channels | ||
channels = [] | ||
|
||
while url: | ||
response = requests.get(url, headers=HEADERS, params=params) | ||
data = response.json() | ||
|
||
if not data.get("ok"): | ||
self.stdout.write(f"Error: {data.get('error')}") | ||
break | ||
|
||
channels.extend(data.get("channels", [])) | ||
cursor = data.get("response_metadata", {}).get("next_cursor") | ||
if cursor: | ||
url = SLACK_API_URL + f"?cursor={cursor}" | ||
else: | ||
url = None | ||
|
||
return channels | ||
|
||
def handle(self, *args, **kwargs): | ||
self.stdout.write("Fetching Slack channels...") | ||
|
||
channels = self.fetch_channels() | ||
for channel in channels: | ||
if channel["name"].startswith("project-"): | ||
project_name = channel["name"].replace("project-", "").capitalize() | ||
|
||
# Update or create project with Slack details | ||
project, created = Project.objects.update_or_create( | ||
name=project_name, | ||
defaults={ | ||
"slack_channel": channel["name"], | ||
"slack_id": channel["id"], | ||
"slack_url": f"https://OWASP.slack.com/archives/{channel['id']}", | ||
}, | ||
) | ||
|
||
if created: | ||
self.stdout.write(f"Created new project: {project_name}") | ||
else: | ||
self.stdout.write(f"Updated existing project: {project_name}") | ||
|
||
self.stdout.write(f"Processed {len(channels)} Slack channels.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("website", "0179_contributorstats"), | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("website", "0180_project_slack"), | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 5.1.4 on 2025-01-19 17:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("website", "0182_merge_20250116_0944"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="SlackChannel", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("slack_channel", models.CharField(max_length=255)), | ||
("slack_id", models.CharField(max_length=255, unique=True)), | ||
("slack_url", models.URLField()), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters