Name work items in the search contract
The results tab is items (SearchType::Items, "items"), a work item's hit is kind item (HitKind::Item), its count is SearchCounts.items, and a hit carries its workspace. The issue names are gone.
- G1T-Session:
- ses_01m566c35sewwsq09vknpxzh49
2 files+37−280/2 viewed
| 2 | 2 | //! | |
| 3 | 3 | //! It covers everything public, and private content the viewer is a member | |
| 4 | 4 | //! of: repositories (name, description, topics, README), code on default | |
| 5 | − | //! branches, issues and pull requests, people and workspaces. Who may see | |
| 5 | + | //! branches, work items and pull requests, people and workspaces. Who may see | |
| 6 | 6 | //! what is decided when the query runs, against the viewer's current | |
| 7 | 7 | //! memberships and each repository's current visibility, never only when | |
| 8 | 8 | //! something was indexed. | |
| ⋯ | |||
| 20 | 20 | pub enum SearchType { | |
| 21 | 21 | Repositories, | |
| 22 | 22 | Code, | |
| 23 | − | Issues, | |
| 23 | + | Items, | |
| 24 | 24 | Pulls, | |
| 25 | 25 | People, | |
| 26 | 26 | } | |
| ⋯ | |||
| 29 | 29 | pub const ALL: [SearchType; 5] = [ | |
| 30 | 30 | SearchType::Repositories, | |
| 31 | 31 | SearchType::Code, | |
| 32 | − | SearchType::Issues, | |
| 32 | + | SearchType::Items, | |
| 33 | 33 | SearchType::Pulls, | |
| 34 | 34 | SearchType::People, | |
| 35 | 35 | ]; | |
| ⋯ | |||
| 38 | 38 | match self { | |
| 39 | 39 | SearchType::Repositories => "repositories", | |
| 40 | 40 | SearchType::Code => "code", | |
| 41 | − | SearchType::Issues => "issues", | |
| 41 | + | SearchType::Items => "items", | |
| 42 | 42 | SearchType::Pulls => "pulls", | |
| 43 | 43 | SearchType::People => "people", | |
| 44 | 44 | } | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | 47 | /// Reads a type as people write it: `repositories`, `repos`, `code`, | |
| 48 | − | /// `issues`, `pulls`, `prs`, `people`, `users`. | |
| 48 | + | /// `items`, `pulls`, `prs`, `people`, `users`. | |
| 49 | 49 | pub fn parse(text: &str) -> Option<SearchType> { | |
| 50 | 50 | match text.trim().to_lowercase().as_str() { | |
| 51 | 51 | "repositories" | "repository" | "repos" | "repo" | "projects" | "project" => Some(SearchType::Repositories), | |
| 52 | 52 | "code" => Some(SearchType::Code), | |
| 53 | − | "issues" | "issue" => Some(SearchType::Issues), | |
| 53 | + | "items" | "item" => Some(SearchType::Items), | |
| 54 | 54 | "pulls" | "pull" | "prs" | "pr" | "pull_requests" | "pull-requests" => Some(SearchType::Pulls), | |
| 55 | 55 | "people" | "users" | "user" | "workspaces" | "workspace" => Some(SearchType::People), | |
| 56 | 56 | _ => None, | |
| ⋯ | |||
| 107 | 107 | pub enum HitKind { | |
| 108 | 108 | Repository, | |
| 109 | 109 | Code, | |
| 110 | − | Issue, | |
| 110 | + | Item, | |
| 111 | 111 | Pull, | |
| 112 | 112 | User, | |
| 113 | 113 | Workspace, | |
| ⋯ | |||
| 123 | 123 | pub title: String, | |
| 124 | 124 | /// Where it is on g1t.sh, as a path: `/acme/web/blob/main/src/app.rs#L12`. | |
| 125 | 125 | pub url: String, | |
| 126 | − | /// The repository, as `owner/name`, for everything but people. | |
| 126 | + | /// The repository, as `owner/name`, for everything but people and | |
| 127 | + | /// workspaces: for a work item, the one it was filed in, if any. | |
| 127 | 128 | #[serde(default)] | |
| 128 | 129 | pub repo: Option<String>, | |
| 130 | + | /// For a work item: its workspace's slug. | |
| 131 | + | #[serde(default)] | |
| 132 | + | pub workspace: Option<String>, | |
| 129 | 133 | /// Whether only members of its workspace can see it. | |
| 130 | 134 | #[serde(default)] | |
| 131 | 135 | pub private: bool, | |
| ⋯ | |||
| 148 | 152 | /// For code: the branch it was read from. | |
| 149 | 153 | #[serde(default, rename = "ref")] | |
| 150 | 154 | pub git_ref: Option<String>, | |
| 151 | − | /// For issues and pull requests. | |
| 155 | + | /// For work items and pull requests. | |
| 152 | 156 | #[serde(default)] | |
| 153 | 157 | pub number: Option<u32>, | |
| 154 | − | /// `open` or `closed` for an issue; `draft`, `open`, `merged` or | |
| 158 | + | /// `open` or `closed` for a work item; `draft`, `open`, `merged` or | |
| 155 | 159 | /// `closed` for a pull request. | |
| 156 | 160 | #[serde(default)] | |
| 157 | 161 | pub state: Option<String>, | |
| 158 | − | /// Who opened the issue or pull request: `g1t` for one g1t made. | |
| 162 | + | /// Who opened the work item or pull request: `g1t` for one g1t made. | |
| 159 | 163 | #[serde(default)] | |
| 160 | 164 | pub author: Option<String>, | |
| 161 | − | /// For an issue or pull request g1t opened: who asked for it. | |
| 165 | + | /// For a work item or pull request g1t opened: who asked for it. | |
| 162 | 166 | #[serde(default)] | |
| 163 | 167 | pub requested_by: Option<String>, | |
| 164 | 168 | #[serde(default)] | |
| ⋯ | |||
| 184 | 188 | title: title.into(), | |
| 185 | 189 | url: url.into(), | |
| 186 | 190 | repo: None, | |
| 191 | + | workspace: None, | |
| 187 | 192 | private: false, | |
| 188 | 193 | description: None, | |
| 189 | 194 | snippet: Vec::new(), | |
| ⋯ | |||
| 209 | 214 | pub struct SearchCounts { | |
| 210 | 215 | pub repositories: u32, | |
| 211 | 216 | pub code: u32, | |
| 212 | − | pub issues: u32, | |
| 217 | + | pub items: u32, | |
| 213 | 218 | pub pulls: u32, | |
| 214 | 219 | pub people: u32, | |
| 215 | 220 | } | |
| ⋯ | |||
| 219 | 224 | match kind { | |
| 220 | 225 | SearchType::Repositories => self.repositories, | |
| 221 | 226 | SearchType::Code => self.code, | |
| 222 | − | SearchType::Issues => self.issues, | |
| 227 | + | SearchType::Items => self.items, | |
| 223 | 228 | SearchType::Pulls => self.pulls, | |
| 224 | 229 | SearchType::People => self.people, | |
| 225 | 230 | } | |
| ⋯ | |||
| 229 | 234 | let slot = match kind { | |
| 230 | 235 | SearchType::Repositories => &mut self.repositories, | |
| 231 | 236 | SearchType::Code => &mut self.code, | |
| 232 | − | SearchType::Issues => &mut self.issues, | |
| 237 | + | SearchType::Items => &mut self.items, | |
| 233 | 238 | SearchType::Pulls => &mut self.pulls, | |
| 234 | 239 | SearchType::People => &mut self.people, | |
| 235 | 240 | }; | |
| ⋯ | |||
| 331 | 336 | assert_eq!(SearchType::parse("prs"), Some(SearchType::Pulls)); | |
| 332 | 337 | assert_eq!(SearchType::parse("Repos"), Some(SearchType::Repositories)); | |
| 333 | 338 | assert_eq!(SearchType::parse("users"), Some(SearchType::People)); | |
| 339 | + | assert_eq!(SearchType::parse("items"), Some(SearchType::Items)); | |
| 340 | + | assert_eq!(SearchType::parse("issues"), None); | |
| 334 | 341 | assert_eq!(SearchType::parse("wiki"), None); | |
| 335 | 342 | } | |
| 336 | 343 | ||
| 4 | 4 | ||
| 5 | 5 | /** | |
| 6 | 6 | * Search across all of g1t: repositories (name, description, topics, | |
| 7 | − | * README), code on default branches, issues and pull requests, people and | |
| 7 | + | * README), code on default branches, work items and pull requests, people and | |
| 8 | 8 | * workspaces. Everything public, and private content the viewer is a member | |
| 9 | 9 | * of, decided when the query runs. Mirrors `crates/contracts/src/search.rs`. | |
| 10 | 10 | */ | |
| 11 | 11 | ||
| 12 | 12 | /** One tab of results. */ | |
| 13 | − | export type SearchType = "repositories" | "code" | "issues" | "pulls" | "people"; | |
| 13 | + | export type SearchType = "repositories" | "code" | "items" | "pulls" | "people"; | |
| 14 | 14 | ||
| 15 | − | export const SEARCH_TYPES: SearchType[] = ["repositories", "code", "issues", "pulls", "people"]; | |
| 15 | + | export const SEARCH_TYPES: SearchType[] = ["repositories", "code", "items", "pulls", "people"]; | |
| 16 | 16 | ||
| 17 | 17 | /** The most results on one page, and how many a page has when none is asked for. */ | |
| 18 | 18 | export const MAX_PER_PAGE = 50; | |
| ⋯ | |||
| 26 | 26 | /** A line of code in a result, numbered from 1. */ | |
| 27 | 27 | export type CodeLine = { number: number; parts: Segment[] }; | |
| 28 | 28 | ||
| 29 | − | export type HitKind = "repository" | "code" | "issue" | "pull" | "user" | "workspace"; | |
| 29 | + | export type HitKind = "repository" | "code" | "item" | "pull" | "user" | "workspace"; | |
| 30 | 30 | ||
| 31 | 31 | /** One result. Which fields are set depends on `kind`. */ | |
| 32 | 32 | export type SiteHit = { | |
| 33 | 33 | kind: HitKind; | |
| 34 | − | /** `acme/web`, a file's path, an issue's title, a person's name. */ | |
| 34 | + | /** `acme/web`, a file's path, a work item's title, a person's name. */ | |
| 35 | 35 | title: string; | |
| 36 | 36 | /** A path on g1t.sh: `/acme/web/blob/main/src/app.rs#L12`. */ | |
| 37 | 37 | url: string; | |
| 38 | − | /** `owner/name`, for everything but people. */ | |
| 38 | + | /** `owner/name`, for everything but people: for a work item, the one it was filed in, if any. */ | |
| 39 | 39 | repo: string | null; | |
| 40 | + | /** For a work item: its workspace's slug. */ | |
| 41 | + | workspace?: string | null; | |
| 40 | 42 | private: boolean; | |
| 41 | 43 | description: string | null; | |
| 42 | 44 | snippet: Segment[]; | |
| ⋯ | |||
| 46 | 48 | language: string | null; | |
| 47 | 49 | ref: string | null; | |
| 48 | 50 | number: number | null; | |
| 49 | − | /** `open`/`closed` for an issue; `draft`/`open`/`merged`/`closed` for a pull request. */ | |
| 51 | + | /** `open`/`closed` for a work item; `draft`/`open`/`merged`/`closed` for a pull request. */ | |
| 50 | 52 | state: string | null; | |
| 51 | − | /** Who opened the issue or pull request: `g1t` for one g1t made. */ | |
| 53 | + | /** Who opened the work item or pull request: `g1t` for one g1t made. */ | |
| 52 | 54 | author: string | null; | |
| 53 | − | /** For an issue or pull request g1t opened: who asked for it. */ | |
| 55 | + | /** For a work item or pull request g1t opened: who asked for it. */ | |
| 54 | 56 | requestedBy?: string | null; | |
| 55 | 57 | labels: string[]; | |
| 56 | 58 | topics: string[]; | |
| ⋯ | |||
| 107 | 109 | query: string, | |
| 108 | 110 | options?: { type?: SearchType | null; page?: number; perPage?: number }, | |
| 109 | 111 | ): Promise<Result<SearchResults>>; | |
| 110 | − | /** A few repositories, issues, pull requests and people, as someone types. */ | |
| 112 | + | /** A few repositories, work items, pull requests and people, as someone types. */ | |
| 111 | 113 | suggest(viewer: Viewer, query: string): Promise<SiteHit[]>; | |
| 112 | 114 | /** Public repositories, recently active or new, by language or topic. */ | |
| 113 | 115 | explore( | |
| ⋯ | |||
| 150 | 152 | return "repositories"; | |
| 151 | 153 | case "code": | |
| 152 | 154 | return "code"; | |
| 153 | − | case "issues": | |
| 154 | − | case "issue": | |
| 155 | − | return "issues"; | |
| 155 | + | case "items": | |
| 156 | + | case "item": | |
| 157 | + | return "items"; | |
| 156 | 158 | case "pulls": | |
| 157 | 159 | case "prs": | |
| 158 | 160 | case "pr": | |
Comments
Sign in to comment.