2023-01-10 04:42:18 +00:00
/ *
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
if you want to view the source , please visit the github repository of this plugin
* /
var _ _defProp = Object . defineProperty ;
var _ _getOwnPropDesc = Object . getOwnPropertyDescriptor ;
var _ _getOwnPropNames = Object . getOwnPropertyNames ;
var _ _hasOwnProp = Object . prototype . hasOwnProperty ;
var _ _export = ( target , all ) => {
for ( var name in all )
_ _defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
} ;
var _ _copyProps = ( to , from , except , desc ) => {
if ( from && typeof from === "object" || typeof from === "function" ) {
for ( let key of _ _getOwnPropNames ( from ) )
if ( ! _ _hasOwnProp . call ( to , key ) && key !== except )
_ _defProp ( to , key , { get : ( ) => from [ key ] , enumerable : ! ( desc = _ _getOwnPropDesc ( from , key ) ) || desc . enumerable } ) ;
}
return to ;
} ;
var _ _toCommonJS = ( mod ) => _ _copyProps ( _ _defProp ( { } , "__esModule" , { value : true } ) , mod ) ;
// main.ts
var main _exports = { } ;
_ _export ( main _exports , {
default : ( ) => MyPlugin ,
retrieveStories : ( ) => retrieveStories
} ) ;
module . exports = _ _toCommonJS ( main _exports ) ;
2023-01-10 17:56:18 +00:00
var import _obsidian4 = require ( "obsidian" ) ;
2023-01-10 04:42:18 +00:00
// src/mappers/storyMapper.ts
function mapStory ( data ) {
return {
id : data . id ,
name : data . name . replace ( "/" , " " ) ,
points : data . estimate ,
description : data . description ,
type : data . story _type ,
url : data . url ,
state : data . current _state
} ;
}
function mapStories ( data ) {
return data . map ( ( d ) => mapStory ( d ) ) ;
}
// src/apiClient.ts
var import _obsidian = require ( "obsidian" ) ;
var TRACKER _URL = "https://www.pivotaltracker.com/services/v5" ;
function generateConfig ( trackerToken , projectId , queryParam ) {
return {
method : "GET" ,
url : ` ${ TRACKER _URL } /projects/ ${ projectId } /stories? ${ queryParam } ` ,
headers : {
"X-TrackerToken" : trackerToken
} ,
contentType : "application/json"
} ;
}
async function getStories ( trackerId , trackerToken , included ) {
try {
const projectId = parseInt ( trackerId ) ;
const response = [ ] ;
if ( included . includeStories ) {
let unstartedStories = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_state=unstarted" ) ) ) ;
let startedStories = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_state=started" ) ) ) ;
response . push ( ... unstartedStories , ... startedStories ) ;
}
if ( included . includeChores ) {
let unstartedChores = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_story_type=chore&with_state=unstarted" ) ) ) ;
let startedChores = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_story_type=chore&with_state=started" ) ) ) ;
response . push ( ... unstartedChores , ... startedChores ) ;
}
if ( included . includeBugs ) {
let unstartedBugs = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_story_type=bug&with_state=unstarted" ) ) ) ;
let startedBugs = JSON . parse ( await ( 0 , import _obsidian . request ) ( generateConfig ( trackerToken , projectId , "with_story_type=bug&with_state=started" ) ) ) ;
response . push ( ... unstartedBugs , ... startedBugs ) ;
}
2023-01-10 16:28:51 +00:00
if ( response . length === 0 ) {
throw new Error ( "No stories available" ) ;
}
2023-01-10 04:42:18 +00:00
let stories = mapStories ( response ) ;
2023-01-10 16:28:51 +00:00
new import _obsidian . Notice ( "Retrieving Stories" ) ;
2023-01-10 04:42:18 +00:00
return stories . filter ( ( story ) => {
const onlyNonAccepted = story . state !== "accepted" ;
if ( included . pointed ) {
return onlyNonAccepted && typeof story . points === "number" ;
}
return onlyNonAccepted ;
} ) ;
} catch ( e ) {
return Promise . reject ( e . message ) ;
}
}
// src/writeOutputToFile.ts
async function writeOutputToFile ( folderPath , markdown , fileName ) {
const modifiedFileName = fileName . replace ( "/" , " " ) ;
const readmePath = ` ${ folderPath } / ${ modifiedFileName } .md ` ;
return this . app . vault . create ( readmePath , markdown ) ;
}
// src/generateMarkdown.ts
var import _obsidian2 = require ( "obsidian" ) ;
function storyToMarkdown ( story ) {
let currentStory = appendLine ( ` ### ${ story . name } [# ${ story . id } ]( ${ story . url } ) ` , newLine ( "## Pivotal Tracker" ) ) ;
if ( story . type === "feature" && story . points ) {
currentStory = appendLine ( newLine ( "#### Points: " + story . points ) , currentStory ) ;
}
if ( story . description ) {
currentStory = appendLine ( "### Description" , currentStory ) ;
currentStory = appendLine ( story . description , currentStory ) ;
}
currentStory = appendLine ( generateTags ( story . type ) , currentStory ) ;
return currentStory ;
}
function newLine ( content ) {
return ` ${ content } \r
` ;
}
function appendLine ( content , destination ) {
return newLine ( ` ${ destination + content } ` ) ;
}
function generateTags ( type ) {
2023-06-06 21:14:55 +00:00
return newLine ( "" ) + newLine ( "" ) + newLine ( "tags" ) + newLine ( "- #pivotal-tracker" ) + newLine ( "- #" + type ) + newLine ( "" ) ;
2023-01-10 04:42:18 +00:00
}
2023-01-10 16:28:51 +00:00
async function generateMarkdown ( folderPath , stories ) {
let storiesIgnored = 0 ;
for ( let feature of stories ) {
2023-01-10 04:42:18 +00:00
await writeOutputToFile ( folderPath , appendLine ( storyToMarkdown ( feature ) , "" ) , feature . name ) . then ( ( ) => {
new import _obsidian2 . Notice ( ` ${ feature . name } Created ` ) ;
} ) . catch ( ( ) => {
2023-01-10 16:28:51 +00:00
storiesIgnored += 1 ;
2023-01-10 04:42:18 +00:00
} ) ;
2023-01-10 16:28:51 +00:00
}
if ( storiesIgnored === stories . length ) {
return new import _obsidian2 . Notice ( "All Stories Ignored, Files Already Exist" ) ;
}
const storiesCreated = stories . length - storiesIgnored ;
new import _obsidian2 . Notice ( ` ${ storiesCreated } ${ storiesCreated > 1 ? "Stories" : "Story" } Created ` ) ;
2023-01-10 04:42:18 +00:00
}
2023-01-10 17:56:18 +00:00
// src/generateFilePath.ts
var import _obsidian3 = require ( "obsidian" ) ;
async function generateFilePath ( folderPath ) {
let currentFolderPath = "" ;
if ( ! await this . app . vault . adapter . exists ( folderPath ) ) {
let path = folderPath . split ( "/" ) ;
if ( path [ 0 ] === "." ) {
path = path . slice ( 1 ) ;
}
for ( let folder of path ) {
if ( folder . trim ( ) ) {
currentFolderPath += folder ;
if ( ! await this . app . vault . exists ( currentFolderPath ) ) {
await this . app . vault . createFolder ( currentFolderPath ) ;
}
currentFolderPath += "/" ;
}
}
new import _obsidian3 . Notice ( "Folders Created For Story Output" ) ;
2023-01-10 18:12:56 +00:00
return currentFolderPath ;
} else {
return folderPath ;
2023-01-10 17:56:18 +00:00
}
}
2023-01-10 04:42:18 +00:00
// main.ts
var DEFAULT _SETTINGS = {
folderPath : "./stories" ,
2023-01-10 16:28:51 +00:00
trackerUserAPIToken : "" ,
trackerAppId : "" ,
2023-01-10 04:42:18 +00:00
includeBugs : true ,
includeChores : true ,
includeStories : true ,
onlyPointedStories : false
} ;
var retrieveStories = async ( settings ) => {
2023-01-10 16:28:51 +00:00
const { trackerUserAPIToken , trackerAppId , folderPath , onlyPointedStories , includeStories , includeChores , includeBugs } = settings ;
2023-01-10 04:42:18 +00:00
const inclusion = { includeStories , includeChores , includeBugs , pointed : onlyPointedStories } ;
2023-01-10 16:28:51 +00:00
const stories = await getStories ( trackerAppId , trackerUserAPIToken , inclusion ) ;
2023-01-10 17:56:18 +00:00
const newFolderPath = await generateFilePath ( folderPath ) ;
await generateMarkdown ( newFolderPath , stories ) ;
2023-01-10 16:28:51 +00:00
} ;
var pullTrackerStories = ( settings ) => {
if ( settings . trackerAppId === "" ) {
2023-01-10 17:56:18 +00:00
return new import _obsidian4 . Notice ( "No APP ID Provided." ) ;
2023-01-10 16:28:51 +00:00
}
if ( settings . trackerUserAPIToken === "" ) {
2023-01-10 17:56:18 +00:00
return new import _obsidian4 . Notice ( "No API Token provided." ) ;
2023-01-10 16:28:51 +00:00
}
retrieveStories ( settings ) . catch ( ( e ) => {
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Notice ( e ) ;
2023-01-10 16:28:51 +00:00
} ) ;
2023-01-10 04:42:18 +00:00
} ;
2023-01-10 17:56:18 +00:00
var MyPlugin = class extends import _obsidian4 . Plugin {
2023-01-10 04:42:18 +00:00
async onload ( ) {
await this . loadSettings ( ) ;
2023-06-06 21:14:55 +00:00
this . addRibbonIcon (
"book-open" ,
"Pull Tracker Stories" ,
( ) => pullTrackerStories ( this . settings )
) ;
2023-01-10 04:42:18 +00:00
this . addCommand ( {
2023-01-10 16:28:51 +00:00
id : "pivotal-tracker-retrieve-stories" ,
name : "Pull Pivotal Tracker Stories" ,
callback : ( ) => pullTrackerStories ( this . settings )
2023-01-10 04:42:18 +00:00
} ) ;
this . addSettingTab ( new TrackerIntegrationSettingTab ( this . app , this ) ) ;
}
async loadSettings ( ) {
this . settings = Object . assign ( { } , DEFAULT _SETTINGS , await this . loadData ( ) ) ;
}
async saveSettings ( ) {
await this . saveData ( this . settings ) ;
}
} ;
2023-01-10 17:56:18 +00:00
var TrackerIntegrationSettingTab = class extends import _obsidian4 . PluginSettingTab {
2023-01-10 04:42:18 +00:00
constructor ( app , plugin ) {
super ( app , plugin ) ;
this . plugin = plugin ;
}
display ( ) {
const { containerEl } = this ;
containerEl . empty ( ) ;
containerEl . createEl ( "h2" , { text : "Settings for Tracker Integration" } ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Tracker User Token" ) . setDesc ( 'To retrieve this, it can be found in your profile settings under "API KEY"' ) . addText ( ( text ) => text . setPlaceholder ( "Enter your API Key" ) . setValue ( this . plugin . settings . trackerUserAPIToken ) . onChange ( async ( value ) => {
2023-01-10 16:28:51 +00:00
this . plugin . settings . trackerUserAPIToken = value ;
2023-01-10 04:42:18 +00:00
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Tracker App ID" ) . setDesc ( "This can be found in the project url bar https://www.pivotaltracker.com/n/projects/<your_project_id>" ) . addText ( ( text ) => text . setPlaceholder ( "Enter your Apps Id" ) . setValue ( this . plugin . settings . trackerAppId ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . trackerAppId = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Folder Path" ) . setDesc ( "This is the folder path to dump the stories it. It will create the folder path for you." ) . addText ( ( text ) => text . setPlaceholder ( "./Path/Name" ) . setValue ( this . plugin . settings . folderPath ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . folderPath = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Only Pointed Stories" ) . setDesc ( "Should only grab pointed stories if it is on." ) . addToggle ( ( ev ) => ev . setValue ( this . plugin . settings . onlyPointedStories ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . onlyPointedStories = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Include Stories" ) . setDesc ( "Should include stories if it is on." ) . addToggle ( ( ev ) => ev . setValue ( this . plugin . settings . includeStories ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . includeStories = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Include Chores" ) . setDesc ( "Should include chores if it is on." ) . addToggle ( ( ev ) => ev . setValue ( this . plugin . settings . includeChores ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . includeChores = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-01-10 17:56:18 +00:00
new import _obsidian4 . Setting ( containerEl ) . setName ( "Include Bugs" ) . setDesc ( "Should include bugs if it is on." ) . addToggle ( ( ev ) => ev . setValue ( this . plugin . settings . includeBugs ) . onChange ( async ( value ) => {
2023-01-10 04:42:18 +00:00
this . plugin . settings . includeBugs = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
}
} ;