Skip to content

Commit 2c40d2f

Browse files
authored
Merge branch 'dev' into topmost
2 parents 9e85d2e + dbba91a commit 2c40d2f

File tree

155 files changed

+1993
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+1993
-527
lines changed

.github/update_release_pr.py

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
from os import getenv
2+
3+
import requests
4+
5+
6+
def get_github_prs(token: str, owner: str, repo: str, label: str = "", state: str = "all") -> list[dict]:
7+
"""
8+
Fetches pull requests from a GitHub repository that match a given milestone and label.
9+
10+
Args:
11+
token (str): GitHub token.
12+
owner (str): The owner of the repository.
13+
repo (str): The name of the repository.
14+
label (str): The label name.
15+
state (str): State of PR, e.g. open, closed, all
16+
17+
Returns:
18+
list: A list of dictionaries, where each dictionary represents a pull request.
19+
Returns an empty list if no PRs are found or an error occurs.
20+
"""
21+
headers = {
22+
"Authorization": f"token {token}",
23+
"Accept": "application/vnd.github.v3+json",
24+
}
25+
26+
milestone_id = None
27+
milestone_url = f"https://api.github.com/repos/{owner}/{repo}/milestones"
28+
params = {"state": "open"}
29+
30+
try:
31+
response = requests.get(milestone_url, headers=headers, params=params)
32+
response.raise_for_status()
33+
milestones = response.json()
34+
35+
if len(milestones) > 2:
36+
print("More than two milestones found, unable to determine the milestone required.")
37+
exit(1)
38+
39+
# milestones.pop()
40+
for ms in milestones:
41+
if ms["title"] != "Future":
42+
milestone_id = ms["number"]
43+
print(f"Gathering PRs with milestone {ms['title']}...")
44+
break
45+
46+
if not milestone_id:
47+
print(f"No suitable milestone found in repository '{owner}/{repo}'.")
48+
exit(1)
49+
50+
except requests.exceptions.RequestException as e:
51+
print(f"Error fetching milestones: {e}")
52+
exit(1)
53+
54+
# This endpoint allows filtering by milestone and label. A PR in GH's perspective is a type of issue.
55+
prs_url = f"https://api.github.com/repos/{owner}/{repo}/issues"
56+
params = {
57+
"state": state,
58+
"milestone": milestone_id,
59+
"labels": label,
60+
"per_page": 100,
61+
}
62+
63+
all_prs = []
64+
page = 1
65+
while True:
66+
try:
67+
params["page"] = page
68+
response = requests.get(prs_url, headers=headers, params=params)
69+
response.raise_for_status() # Raise an exception for HTTP errors
70+
prs = response.json()
71+
72+
if not prs:
73+
break # No more PRs to fetch
74+
75+
# Check for pr key since we are using issues endpoint instead.
76+
all_prs.extend([item for item in prs if "pull_request" in item])
77+
page += 1
78+
79+
except requests.exceptions.RequestException as e:
80+
print(f"Error fetching pull requests: {e}")
81+
exit(1)
82+
83+
return all_prs
84+
85+
86+
def get_prs(pull_request_items: list[dict], label: str = "", state: str = "all") -> list[dict]:
87+
"""
88+
Returns a list of pull requests after applying the label and state filters.
89+
90+
Args:
91+
pull_request_items (list[dict]): List of PR items.
92+
label (str): The label name.
93+
state (str): State of PR, e.g. open, closed, all
94+
95+
Returns:
96+
list: A list of dictionaries, where each dictionary represents a pull request.
97+
Returns an empty list if no PRs are found.
98+
"""
99+
pr_list = []
100+
count = 0
101+
for pr in pull_request_items:
102+
if pr["state"] == state and [item for item in pr["labels"] if item["name"] == label]:
103+
pr_list.append(pr)
104+
count += 1
105+
106+
print(f"Found {count} PRs with {label if label else 'no'} label and state as {state}")
107+
108+
return pr_list
109+
110+
111+
def get_pr_descriptions(pull_request_items: list[dict]) -> str:
112+
"""
113+
Returns the concatenated string of pr title and number in the format of
114+
'- PR title 1 #3651
115+
- PR title 2 #3652
116+
- PR title 3 #3653
117+
'
118+
119+
Args:
120+
pull_request_items (list[dict]): List of PR items.
121+
122+
Returns:
123+
str: a string of PR titles and numbers
124+
"""
125+
description_content = ""
126+
for pr in pull_request_items:
127+
description_content += f"- {pr['title']} #{pr['number']}\n"
128+
129+
return description_content
130+
131+
132+
def update_pull_request_description(token: str, owner: str, repo: str, pr_number: int, new_description: str) -> None:
133+
"""
134+
Updates the description (body) of a GitHub Pull Request.
135+
136+
Args:
137+
token (str): Token.
138+
owner (str): The owner of the repository.
139+
repo (str): The name of the repository.
140+
pr_number (int): The number of the pull request to update.
141+
new_description (str): The new content for the PR's description.
142+
143+
Returns:
144+
dict or None: The updated PR object (as a dictionary) if successful,
145+
None otherwise.
146+
"""
147+
headers = {
148+
"Authorization": f"token {token}",
149+
"Accept": "application/vnd.github.v3+json",
150+
"Content-Type": "application/json",
151+
}
152+
153+
url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}"
154+
155+
payload = {"body": new_description}
156+
157+
print(f"Attempting to update PR #{pr_number} in {owner}/{repo}...")
158+
print(f"URL: {url}")
159+
160+
try:
161+
response = None
162+
response = requests.patch(url, headers=headers, json=payload)
163+
response.raise_for_status()
164+
165+
print(f"Successfully updated PR #{pr_number}.")
166+
167+
except requests.exceptions.RequestException as e:
168+
print(f"Error updating pull request #{pr_number}: {e}")
169+
if response is not None:
170+
print(f"Response status code: {response.status_code}")
171+
print(f"Response text: {response.text}")
172+
exit(1)
173+
174+
175+
if __name__ == "__main__":
176+
github_token = getenv("GITHUB_TOKEN")
177+
178+
if not github_token:
179+
print("Error: GITHUB_TOKEN environment variable not set.")
180+
exit(1)
181+
182+
repository_owner = "flow-launcher"
183+
repository_name = "flow.launcher"
184+
state = "all"
185+
186+
print(f"Fetching {state} PRs for {repository_owner}/{repository_name} ...")
187+
188+
pull_requests = get_github_prs(github_token, repository_owner, repository_name)
189+
190+
if not pull_requests:
191+
print("No matching pull requests found")
192+
exit(1)
193+
194+
print(f"\nFound total of {len(pull_requests)} pull requests")
195+
196+
release_pr = get_prs(pull_requests, "release", "open")
197+
198+
if len(release_pr) != 1:
199+
print(f"Unable to find the exact release PR. Returned result: {release_pr}")
200+
exit(1)
201+
202+
print(f"Found release PR: {release_pr[0]['title']}")
203+
204+
enhancement_prs = get_prs(pull_requests, "enhancement", "closed")
205+
bug_fix_prs = get_prs(pull_requests, "bug", "closed")
206+
207+
description_content = "# Release notes\n"
208+
description_content += f"## Features\n{get_pr_descriptions(enhancement_prs)}" if enhancement_prs else ""
209+
description_content += f"## Bug fixes\n{get_pr_descriptions(bug_fix_prs)}" if bug_fix_prs else ""
210+
211+
update_pull_request_description(
212+
github_token, repository_owner, repository_name, release_pr[0]["number"], description_content
213+
)
214+
215+
print(f"PR content updated to:\n{description_content}")

.github/workflows/release_deploy.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
3+
name: New Release Deployments
4+
on:
5+
release:
6+
types: [published]
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy-website:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Trigger dispatch event for deploying website
14+
run: |
15+
http_status=$(curl -L -f -s -o /dev/null -w "%{http_code}" \
16+
-X POST \
17+
-H "Accept: application/vnd.github+json" \
18+
-H "Authorization: Bearer ${{ secrets.DEPLOY_FLOW_WEBSITE }}" \
19+
https://api.github.com/repos/Flow-Launcher/flow-launcher.github.io/dispatches \
20+
-d '{"event_type":"deploy"}')
21+
if [ "$http_status" -ne 204 ]; then echo "Error: Deploy website failed, HTTP status code is $http_status"; exit 1; fi
22+
23+
publish-chocolatey:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Trigger dispatch event for publishing to Chocolatey
27+
run: |
28+
http_status=$(curl -L -f -s -o /dev/null -w "%{http_code}" \
29+
-X POST \
30+
-H "Accept: application/vnd.github+json" \
31+
-H "Authorization: Bearer ${{ secrets.Publish_Chocolatey }}" \
32+
https://api.github.com/repos/Flow-Launcher/chocolatey-package/dispatches \
33+
-d '{"event_type":"publish"}')
34+
if [ "$http_status" -ne 204 ]; then echo "Error: Publish Chocolatey package failed, HTTP status code is $http_status"; exit 1; fi

.github/workflows/release_pr.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Update release PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
branches:
7+
- master
8+
workflow_dispatch:
9+
10+
jobs:
11+
update-pr:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
19+
20+
- name: Run release PR update
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.PR_TOKEN }}
23+
run: |
24+
pip install requests -q
25+
python3 ./.github/update_release_pr.py

.github/workflows/website_deploy.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,21 @@ private static void UpdatePluginDirectory(List<PluginMetadata> metadatas)
187187
{
188188
if (AllowedLanguage.IsDotNet(metadata.Language))
189189
{
190+
if (string.IsNullOrEmpty(metadata.AssemblyName))
191+
{
192+
API.LogWarn(ClassName, $"AssemblyName is empty for plugin with metadata: {metadata.Name}");
193+
continue; // Skip if AssemblyName is not set, which can happen for erroneous plugins
194+
}
190195
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.AssemblyName);
191196
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, metadata.AssemblyName);
192197
}
193198
else
194199
{
200+
if (string.IsNullOrEmpty(metadata.Name))
201+
{
202+
API.LogWarn(ClassName, $"Name is empty for plugin with metadata: {metadata.Name}");
203+
continue; // Skip if Name is not set, which can happen for erroneous plugins
204+
}
195205
metadata.PluginSettingsDirectoryPath = Path.Combine(DataLocation.PluginSettingsDirectory, metadata.Name);
196206
metadata.PluginCacheDirectoryPath = Path.Combine(DataLocation.PluginCacheDirectory, metadata.Name);
197207
}

Flow.Launcher.Core/Plugin/QueryBuilder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
1616
Search = string.Empty,
1717
RawQuery = string.Empty,
1818
SearchTerms = Array.Empty<string>(),
19-
ActionKeyword = string.Empty
19+
ActionKeyword = string.Empty,
20+
IsHomeQuery = true
2021
};
2122
}
2223

@@ -53,7 +54,8 @@ public static Query Build(string text, Dictionary<string, PluginPair> nonGlobalP
5354
Search = search,
5455
RawQuery = rawQuery,
5556
SearchTerms = searchTerms,
56-
ActionKeyword = actionKeyword
57+
ActionKeyword = actionKeyword,
58+
IsHomeQuery = false
5759
};
5860
}
5961
}

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ public static async Task<string> GetAsync([NotNull] Uri url, CancellationToken t
182182
public static Task<Stream> GetStreamAsync([NotNull] string url,
183183
CancellationToken token = default) => GetStreamAsync(new Uri(url), token);
184184

185-
186185
/// <summary>
187186
/// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation.
188187
/// </summary>
@@ -212,7 +211,14 @@ public static async Task<HttpResponseMessage> GetResponseAsync([NotNull] Uri url
212211
/// </summary>
213212
public static async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken token = default)
214213
{
215-
return await client.SendAsync(request, completionOption, token);
214+
try
215+
{
216+
return await client.SendAsync(request, completionOption, token);
217+
}
218+
catch (System.Exception)
219+
{
220+
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
221+
}
216222
}
217223
}
218224
}

Flow.Launcher.Infrastructure/NativeMethods.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SystemParametersInfo
2222

2323
SetForegroundWindow
2424

25-
GetWindowLong
25+
WINDOW_LONG_PTR_INDEX
2626
GetForegroundWindow
2727
GetDesktopWindow
2828
GetShellWindow
@@ -57,3 +57,7 @@ LOCALE_TRANSIENT_KEYBOARD1
5757
LOCALE_TRANSIENT_KEYBOARD2
5858
LOCALE_TRANSIENT_KEYBOARD3
5959
LOCALE_TRANSIENT_KEYBOARD4
60+
61+
SHParseDisplayName
62+
SHOpenFolderAndSelectItems
63+
CoTaskMemFree

0 commit comments

Comments
 (0)