Skip to content

Added my-issues function#2

Open
SiMiZZZ wants to merge 1 commit into
masterfrom
my-issues
Open

Added my-issues function#2
SiMiZZZ wants to merge 1 commit into
masterfrom
my-issues

Conversation

@SiMiZZZ

@SiMiZZZ SiMiZZZ commented Feb 26, 2026

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main.rs

println!("🔍 Fetching your assigned issues...");
match get_my_issues(&JiraClient::new(&config), project.as_deref(), all).await {
Ok(issues) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok(issues) if issues.is_empty() => {1}
Ok(issues) => {2}

Comment thread src/jira_client.rs Outdated
pub async fn get_my_issues(
jira_client: &JiraClient,
project: Option<&str>,
include_done: bool,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В сервис просочился пользовательский флаг. Стоит enum сделать и выбирать его элементы в зависимости от флага пользователя из команды

Comment thread src/jira_client.rs Outdated
project: Option<&str>,
include_done: bool,
) -> Result<Vec<Issue>, JiraClientError> {
let mut jql = "assignee = currentUser()".to_string();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

сбор jql если вынести в отдельную функцию (а лучше Trait builder) и даже можно тестами отдельно покрыть.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct JQLBuilder {
    inner: String
}

Comment thread src/jira_client.rs Outdated
);

let mut all_issues = Vec::new();
let max_results = 50;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно в const вынести на уровень модуля

Comment thread src/jira_client.rs
jql.push_str(" ORDER BY updated DESC");

let api_url = format!(
"{}/rest/api/2/search",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: можно использовать тип Url и соединять в него пути вместо форматирования строчек.

Comment thread src/jira_client.rs Outdated
let search_response: SearchResponse =
response.json().await.map_err(|_| JiraClientError::Parse)?;

let fetched = search_response.issues.len() as i32;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем так много, i16 не хватит? также подходит usize

Comment thread src/jql.rs

#[derive(Debug, Clone)]
pub struct JqlBuildError {
pub message: String,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А лучше enum с thiserror, чем разные сообщения, которые не разбиты по кейсам

Comment thread src/jql.rs
impl std::error::Error for JqlBuildError {}

/// Project keys must be uppercase alphanumeric + underscore only.
fn validate_project_key(key: &str) -> Result<(), JqlBuildError> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse dont validate. Тут стоит завести тип ProjectKey(String), который парсится из &str, String через FromString, TryFrom (как удобнее)

Comment thread src/jql.rs

/// Build the final JQL string.
pub fn build(self) -> String {
let mut jql = String::new();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут мутация строки и ниже цикл foreach. Для раста это малость неоптимально и будет сводить компилятор с ума, так как нет оптимизаций итераторами. Предлагаю использовать коллекцию conditions через iter, каждое значение смаппить в строчку через map(|conj| write!(...)) и после всего этого применить join на результат итератора

Comment thread src/jql.rs
let _ = write!(jql, "{} {} {}", cond.field, cond.operator, cond.value);
}

if !self.order_by.is_empty() {

@LEVLLN LEVLLN Mar 19, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вижу, что в два-три этапа собирается jql, но можно все разные части в разных переменных строк собрать. А на выходе соединить все части эти. Сборка разных частей строк спокойно делится на функции приватные и для них можно писать десты в docstring :)

Comment thread src/jql.rs
/// Add a condition joined by OR.
#[allow(dead_code)]
pub fn or(mut self, field: Field, op: Operator, value: Value) -> Self {
let conjunction = if self.conditions.is_empty() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.conditions.is_empty().then(|| Some(Conjunction::Or))

Comment thread src/jql.rs

/// Right-hand side value in a JQL condition.
#[derive(Debug, Clone)]
#[allow(dead_code)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а почему dead_code?

Comment thread src/jql.rs

/// Add a condition joined by AND (or as the first condition).
pub fn and(mut self, field: Field, op: Operator, value: Value) -> Self {
let conjunction = if self.conditions.is_empty() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.conditions.is_empty().then(|| Some(Conjunction::AND))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants