diff --git a/frontend/src/services/nizkctf/github.js b/frontend/src/services/nizkctf/github.js index 1e7fc4a..df6f2c4 100644 --- a/frontend/src/services/nizkctf/github.js +++ b/frontend/src/services/nizkctf/github.js @@ -78,12 +78,14 @@ export default class GitHub { }; } - async listPullRequests(repoName, username, state) { + async listPullRequests(repoName, state, filter, username = null) { const status = state === "opened" ? "open" : state; const { owner, repo } = repoNameHandler(repoName); - const query = `is:pr+repo:${owner}/${repo}+author:${username}+state:${status}`; + const query = filter + ? `${filter}+is:pr+repo:${owner}/${repo}+state:${status}` + : `is:pr+repo:${owner}/${repo}+author:${username}+state:${status}`; const { data } = await this.octokit.search.issuesAndPullRequests({ q: query diff --git a/frontend/src/services/nizkctf/gitlab.js b/frontend/src/services/nizkctf/gitlab.js index 2c268a1..deb0bf0 100644 --- a/frontend/src/services/nizkctf/gitlab.js +++ b/frontend/src/services/nizkctf/gitlab.js @@ -86,6 +86,7 @@ export default class GitLab { }; } async listPullRequests(projectId, authorUsername, state) { + // TODO implements filter const response = await this.api.MergeRequests.all({ projectId, authorUsername, diff --git a/frontend/src/services/nizkctf/index.js b/frontend/src/services/nizkctf/index.js index 9a6d33c..27bb2a6 100644 --- a/frontend/src/services/nizkctf/index.js +++ b/frontend/src/services/nizkctf/index.js @@ -57,7 +57,19 @@ export default class NIZKCTF { const proof = await this._createProof(challenge, keys.privateKey); const path = getTeamPath(this.team.name); - const message = `Proof: found flag for ${challenge.id}`; + const message = `Proof: found flag for ${challenge.id} - ${path}`; + + const list = await this.api.listPullRequests( + this.upstream, + "opened", + `${message}:in:title` + ); + + if (list.length > 0) { + throw new Error( + "Your team has already sent this flag and it is in the bot's processing queue" + ); + } const newProof = Buffer.from(proof).toString("base64");