Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions evaldo/builtins_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ var Builtins_io = map[string]*env.Builtin{

// Args:
// * url: uri representing the HTTPS URL to request
// * method: word specifying the HTTP method (e.g., 'GET', 'POST')
// * method: word specifying the HTTP method (e.g., 'GET', 'POST', 'PUT', 'DELETE')
// * data: string containing the request body
// Returns:
// * native https-request object
Expand All @@ -1307,7 +1307,7 @@ var Builtins_io = map[string]*env.Builtin{
switch method := arg1.(type) {
case env.Word:
method1 := ps.Idx.GetWord(method.Index)
if !(method1 == "GET" || method1 == "POST") {
if !(method1 == "GET" || method1 == "POST" || method1 == "PUT" || method1 == "DELETE") {
ps.FailureFlag = true
return MakeBuiltinError(ps, "Wrong method.", "https-uri//Request")
}
Expand Down
1 change: 1 addition & 0 deletions evaldo/builtins_term.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ var Builtins_term = map[string]*env.Builtin{

// Wait for the spinner to finish
<-spinnerDone
fmt.Println("")
return ps.Res
default:
return MakeArgError(ps, 1, []env.Type{env.StringType}, "spin-it")
Expand Down
58 changes: 58 additions & 0 deletions examples/github/merge-dependabots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import time
import requests
from rich.console import Console

# 1. Configuration
try:
with open(".apitoken", "r") as f:
TOK = f.read().strip()
except FileNotFoundError:
print("Error: .apitoken file not found.")
exit(1)

BOT = "dependabot[bot]"
REPO = "refaktor/rye"
URL = "https://api.github.com/repos/"
HEADERS = {
"Authorization": f"Bearer {TOK}",
"Accept": "application/vnd.github+json"
}

console = Console()

def do_merge(num):
"""Merges a specific PR number using the squash method."""
merge_url = f"{URL}{REPO}/pulls/{num}/merge"
data = {"merge_method": "squash"}
response = requests.put(merge_url, headers=HEADERS, json=data)
return response.status_code

def main():
# 2. Fetch Open PRs
with console.status("[bold blue]Fetching pull requests...") as status:
response = requests.get(f"{URL}{REPO}/pulls?state=open", headers=HEADERS)
response.raise_for_status()
prs = response.json()

# 3. Filter for the bot
bot_prs = [pr for pr in prs if pr["user"]["login"] == BOT]
console.print(f"[green]{len(bot_prs)} pull requests found.")

# 4. Loop and Merge
for pr in bot_prs:
num = pr["number"]

# Merge action with spinner
with console.status(f"[bold yellow]Merging #{num}...") as status:
status_code = do_merge(num)
if status_code == 200:
console.print(f"Successfully merged #{num} :white_check_mark:")
else:
console.print(f"Failed to merge #{num} (Status: {status_code}) :x:")

# Sleep action with spinner
with console.status("[bold cyan]Sleeping for rebase...") as status:
time.sleep(60)

if __name__ == "__main__":
main()
26 changes: 26 additions & 0 deletions examples/github/merge-dependabots.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; # Script that merges all dependabot PR-s

tok: trim Read %.apitoken
bot: "dependabot[bot]"
repo: "refaktor/rye"
url: https://api.github.com/repos/

set-headers: fn { req } {
.Header! 'Authorization join [ "Bearer " tok ]
|Header! 'Accept "application/vnd.github+json"
}

do-merge: fn { num } {
Request ( url ++ repo ++ "/pulls/" ++ num ++ "/merge" ) 'PUT `{ "merge_method": "squash" }`
|set-headers |Call |Reader
}

Request ( url ++ repo ++ "/pulls?state=open" ) 'GET ""
|set-headers
|Call .Reader .Read\string .parse-json
|filter { -> "user" -> "login" |= bot }
|pass { .length? .embed "{} pull requests found" |print }
|for { -> "number" ::num ,
term/spin-it "Merging " ++ num { do-merge num }
term/spin-it "Sleeping for rebases to happen" { sleep 1 .minutes }
}
5 changes: 5 additions & 0 deletions examples/makedirs.rye
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


a:: split "one/two/three" "/"
path:: ""
walk a { ::b ( "/" ++ first b ) .append! 'path , os/mkdir to-uri path , b .rest }