-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nverges/4-import-with-estimates
4 import with estimates
- Loading branch information
Showing
11 changed files
with
201 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const ESTIMATION_SCALES = { | ||
exponential: [0, 1, 2, 4, 8, 16], | ||
fibonacci: [0, 1, 2, 3, 5, 8], | ||
linear: [0, 1, 2, 3, 4, 5], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import linearClient from "../../config/client.mjs"; | ||
import { ESTIMATION_SCALES } from "./estimation_scales.js"; | ||
|
||
export function findClosestEstimate(value, scale) { | ||
if (!scale || !value) return null; | ||
|
||
const numericValue = Number(value); | ||
if (isNaN(numericValue)) return null; | ||
|
||
return scale.reduce((closest, current) => { | ||
return Math.abs(current - numericValue) < Math.abs(closest - numericValue) ? current : closest; | ||
}); | ||
} | ||
|
||
async function fetchEstimatesForTeam({ teamId }) { | ||
if (!teamId) { | ||
throw new Error("teamId is required"); | ||
} | ||
|
||
try { | ||
const team = await linearClient.team(teamId); | ||
const issueEstimationType = await team.issueEstimationType; | ||
|
||
const estimationScale = ESTIMATION_SCALES[issueEstimationType] || null; | ||
|
||
const data = { | ||
type: issueEstimationType, | ||
scale: estimationScale, | ||
}; | ||
|
||
return data; | ||
} catch (error) { | ||
console.error("Error fetching estimates:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
export default fetchEstimatesForTeam; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ENABLE_DETAILED_LOGGING } from "../../config/config.js"; | ||
import { ESTIMATION_SCALES } from "./estimation_scales.js"; | ||
import chalk from "chalk"; | ||
|
||
export function findClosestEstimate(value, estimationScale) { | ||
if (!estimationScale || !value) return null; | ||
|
||
const scale = ESTIMATION_SCALES[estimationScale]; | ||
const numericValue = Number(value); | ||
|
||
if (isNaN(numericValue)) return null; | ||
|
||
if (ENABLE_DETAILED_LOGGING) { | ||
console.log("value", value); | ||
console.log(chalk.magenta("estimationScale"), estimationScale); | ||
console.log(chalk.magenta("scale"), scale); | ||
} | ||
|
||
if (scale.includes(numericValue)) { | ||
if (ENABLE_DETAILED_LOGGING) { | ||
console.log(chalk.magenta("exact match found:"), numericValue); | ||
} | ||
return numericValue; | ||
} | ||
|
||
let closest = scale[0]; | ||
let minDiff = Math.abs(scale[0] - numericValue); | ||
|
||
for (let i = 1; i < scale.length; i++) { | ||
const diff = Math.abs(scale[i] - numericValue); | ||
if (diff < minDiff) { | ||
minDiff = diff; | ||
closest = scale[i]; | ||
} | ||
} | ||
|
||
if (ENABLE_DETAILED_LOGGING) { | ||
console.log(chalk.magenta("closest"), closest); | ||
} | ||
|
||
return closest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.