Skip to content

Commit 37d7f37

Browse files
Copilotbrunoborges
andcommitted
Refactor to eliminate duplication: SessionListFilter extends SessionContext
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 17f1423 commit 37d7f37

3 files changed

Lines changed: 27 additions & 71 deletions

File tree

src/main/java/com/github/copilot/sdk/events/SessionContextChangedEvent.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
88
import com.fasterxml.jackson.annotation.JsonProperty;
9+
import com.github.copilot.sdk.json.SessionContext;
910

1011
/**
1112
* Event: session.context_changed
@@ -19,23 +20,18 @@
1920
public final class SessionContextChangedEvent extends AbstractSessionEvent {
2021

2122
@JsonProperty("data")
22-
private SessionContextChangedData data;
23+
private SessionContext data;
2324

2425
@Override
2526
public String getType() {
2627
return "session.context_changed";
2728
}
2829

29-
public SessionContextChangedData getData() {
30+
public SessionContext getData() {
3031
return data;
3132
}
3233

33-
public void setData(SessionContextChangedData data) {
34+
public void setData(SessionContext data) {
3435
this.data = data;
3536
}
36-
37-
@JsonIgnoreProperties(ignoreUnknown = true)
38-
public record SessionContextChangedData(@JsonProperty("cwd") String cwd, @JsonProperty("gitRoot") String gitRoot,
39-
@JsonProperty("repository") String repository, @JsonProperty("branch") String branch) {
40-
}
4137
}

src/main/java/com/github/copilot/sdk/json/SessionContext.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public String getCwd() {
4444
*
4545
* @param cwd
4646
* the current working directory path
47+
* @return this instance for method chaining
4748
*/
48-
public void setCwd(String cwd) {
49+
public SessionContext setCwd(String cwd) {
4950
this.cwd = cwd;
51+
return this;
5052
}
5153

5254
/**
@@ -63,9 +65,11 @@ public String getGitRoot() {
6365
*
6466
* @param gitRoot
6567
* the git root path
68+
* @return this instance for method chaining
6669
*/
67-
public void setGitRoot(String gitRoot) {
70+
public SessionContext setGitRoot(String gitRoot) {
6871
this.gitRoot = gitRoot;
72+
return this;
6973
}
7074

7175
/**
@@ -82,9 +86,11 @@ public String getRepository() {
8286
*
8387
* @param repository
8488
* the repository in "owner/repo" format
89+
* @return this instance for method chaining
8590
*/
86-
public void setRepository(String repository) {
91+
public SessionContext setRepository(String repository) {
8792
this.repository = repository;
93+
return this;
8894
}
8995

9096
/**
@@ -101,8 +107,10 @@ public String getBranch() {
101107
*
102108
* @param branch
103109
* the branch name
110+
* @return this instance for method chaining
104111
*/
105-
public void setBranch(String branch) {
112+
public SessionContext setBranch(String branch) {
106113
this.branch = branch;
114+
return this;
107115
}
108116
}

src/main/java/com/github/copilot/sdk/json/SessionListFilter.java

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
package com.github.copilot.sdk.json;
66

7-
import com.fasterxml.jackson.annotation.JsonInclude;
8-
import com.fasterxml.jackson.annotation.JsonProperty;
9-
107
/**
118
* Filter options for listing sessions.
129
* <p>
13-
* Allows filtering sessions by working directory context fields such as cwd,
14-
* git root, repository, or branch.
10+
* Extends {@link SessionContext} to provide filtering capabilities with fluent
11+
* setter methods that return the filter instance for method chaining.
1512
*
1613
* <h2>Example Usage</h2>
1714
*
@@ -28,29 +25,7 @@
2825
* @see com.github.copilot.sdk.CopilotClient#listSessions(SessionListFilter)
2926
* @since 1.0.0
3027
*/
31-
@JsonInclude(JsonInclude.Include.NON_NULL)
32-
public class SessionListFilter {
33-
34-
@JsonProperty("cwd")
35-
private String cwd;
36-
37-
@JsonProperty("gitRoot")
38-
private String gitRoot;
39-
40-
@JsonProperty("repository")
41-
private String repository;
42-
43-
@JsonProperty("branch")
44-
private String branch;
45-
46-
/**
47-
* Gets the current working directory filter.
48-
*
49-
* @return the cwd filter, or {@code null} if not set
50-
*/
51-
public String getCwd() {
52-
return cwd;
53-
}
28+
public class SessionListFilter extends SessionContext {
5429

5530
/**
5631
* Sets the filter for exact cwd match.
@@ -59,71 +34,48 @@ public String getCwd() {
5934
* the current working directory to filter by
6035
* @return this filter for method chaining
6136
*/
37+
@Override
6238
public SessionListFilter setCwd(String cwd) {
63-
this.cwd = cwd;
39+
super.setCwd(cwd);
6440
return this;
6541
}
6642

67-
/**
68-
* Gets the git root filter.
69-
*
70-
* @return the git root filter, or {@code null} if not set
71-
*/
72-
public String getGitRoot() {
73-
return gitRoot;
74-
}
75-
7643
/**
7744
* Sets the filter for git root directory.
7845
*
7946
* @param gitRoot
8047
* the git root path to filter by
8148
* @return this filter for method chaining
8249
*/
50+
@Override
8351
public SessionListFilter setGitRoot(String gitRoot) {
84-
this.gitRoot = gitRoot;
52+
super.setGitRoot(gitRoot);
8553
return this;
8654
}
8755

88-
/**
89-
* Gets the repository filter.
90-
*
91-
* @return the repository filter, or {@code null} if not set
92-
*/
93-
public String getRepository() {
94-
return repository;
95-
}
96-
9756
/**
9857
* Sets the filter for repository (in "owner/repo" format).
9958
*
10059
* @param repository
10160
* the repository identifier to filter by
10261
* @return this filter for method chaining
10362
*/
63+
@Override
10464
public SessionListFilter setRepository(String repository) {
105-
this.repository = repository;
65+
super.setRepository(repository);
10666
return this;
10767
}
10868

109-
/**
110-
* Gets the branch filter.
111-
*
112-
* @return the branch filter, or {@code null} if not set
113-
*/
114-
public String getBranch() {
115-
return branch;
116-
}
117-
11869
/**
11970
* Sets the filter for git branch.
12071
*
12172
* @param branch
12273
* the branch name to filter by
12374
* @return this filter for method chaining
12475
*/
76+
@Override
12577
public SessionListFilter setBranch(String branch) {
126-
this.branch = branch;
78+
super.setBranch(branch);
12779
return this;
12880
}
12981
}

0 commit comments

Comments
 (0)