-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
57 lines (44 loc) · 1.83 KB
/
lambda_function.py
File metadata and controls
57 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import asyncio
import logging
import os
from typing import Optional
from service.GithubAutoFollowNUnfollow import GithubAutoFollowNUnfollow
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
def _parse_csv(value: Optional[str]) -> list[str]:
if not value:
return []
return [item.strip() for item in value.split(",") if item.strip()]
def _as_bool(value: Optional[str]) -> bool:
return (value or "").strip().lower() in ("1", "true", "yes", "on")
def lambda_handler(event, context):
try:
username = os.getenv("GITHUB_USERNAME")
token = os.getenv("GITHUB_TOKEN")
api_url = os.getenv("GITHUB_API_URL", "https://api.github.com")
concurrency = int(os.getenv("CONCURRENCY", "5"))
dry_run = _as_bool(os.getenv("DRY_RUN"))
exclude_follow = _parse_csv(os.getenv("EXCLUDE_FOLLOW"))
exclude_unfollow = _parse_csv(os.getenv("EXCLUDE_UNFOLLOW"))
if not username or not token:
msg = "Please setup environment variables before execute"
logger.error(msg)
return {"statusCode": 400, "body": {"error": msg}}
service = GithubAutoFollowNUnfollow(
username=username,
token=token,
api_url=api_url,
concurrency=concurrency,
dry_run=dry_run,
exclude_follow=exclude_follow,
exclude_unfollow=exclude_unfollow,
)
summary = asyncio.run(service.run())
return {
"statusCode": 200,
"body": {"message": "Github Follow/Unfollow completed", "summary": summary},
}
except Exception as e:
error_msg = f"Unexpected error occurred: {e}"
logger.error(error_msg)
return {"statusCode": 500, "body": {"error": error_msg}}