-
Notifications
You must be signed in to change notification settings - Fork 4
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 #11 from kothar/privacy_setting
Implement new privacy settings
- Loading branch information
Showing
11 changed files
with
365 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
cmd/asana/asana | ||
/.idea | ||
/.idea | ||
|
||
.DS_Store |
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 @@ | ||
golang 1.23.0 |
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 |
---|---|---|
@@ -1,176 +1,180 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/jessevdk/go-flags" | ||
"log" | ||
"mime" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
|
||
"bitbucket.org/mikehouston/asana-go" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/jessevdk/go-flags" | ||
"log" | ||
"mime" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
|
||
"bitbucket.org/mikehouston/asana-go" | ||
) | ||
|
||
var ( | ||
True = true | ||
) | ||
|
||
var options struct { | ||
Token string `long:"token" description:"Personal Access Token used to authorize access to the API" env:"ASANA_TOKEN" required:"true"` | ||
Token string `long:"token" description:"Personal Access Token used to authorize access to the API" env:"ASANA_TOKEN" required:"true"` | ||
|
||
Workspace []string `long:"workspace" short:"w" description:"Workspace to access"` | ||
Project []string `long:"project" short:"p" description:"Project to access"` | ||
Task []string `long:"task" short:"t" description:"Task to access"` | ||
Workspace []string `long:"workspace" short:"w" description:"Workspace to access"` | ||
Project []string `long:"project" short:"p" description:"Project to access"` | ||
Task []string `long:"task" short:"t" description:"Task to access"` | ||
|
||
Attach string `long:"attach" description:"Attach a file to a task"` | ||
AddSection string `long:"add-section" description:"Add a new section to a project"` | ||
Attach string `long:"attach" description:"Attach a file to a task"` | ||
AddSection string `long:"add-section" description:"Add a new section to a project"` | ||
|
||
Stories bool `long:"stories" description:"List stories for a task"` | ||
Clean bool `long:"clean" description:"Clean all stories from a task"` | ||
Stories bool `long:"stories" description:"List stories for a task"` | ||
Clean bool `long:"clean" description:"Clean all stories from a task"` | ||
|
||
Debug bool `short:"d" long:"debug" description:"Show debug information"` | ||
Verbose []bool `short:"v" long:"verbose" description:"Show verbose output"` | ||
Debug bool `short:"d" long:"debug" description:"Show debug information"` | ||
Verbose []bool `short:"v" long:"verbose" description:"Show verbose output"` | ||
} | ||
|
||
func authenticate(req *http.Request) (*url.URL, error) { | ||
req.Header.Add("Authorization", "Bearer "+options.Token) | ||
return nil, nil | ||
req.Header.Add("Authorization", "Bearer "+options.Token) | ||
return nil, nil | ||
} | ||
|
||
func check(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func main() { | ||
if _, err := flags.Parse(&options); err != nil { | ||
return | ||
} | ||
|
||
// Create a client | ||
client := asana.NewClient(&http.Client{ | ||
Transport: &http.Transport{ | ||
Proxy: authenticate, | ||
}, | ||
}) | ||
if options.Debug { | ||
client.Debug = true | ||
client.DefaultOptions.Pretty = true | ||
} | ||
client.Verbose = options.Verbose | ||
client.DefaultOptions.Enable = []asana.Feature{asana.StringIDs, asana.NewSections, asana.NewTaskSubtypes} | ||
|
||
// Load a task object | ||
if options.Task == nil { | ||
|
||
// Load a project object | ||
if options.Project == nil { | ||
|
||
// Load a workspace object | ||
if options.Workspace == nil { | ||
check(ListWorkspaces(client)) | ||
return | ||
} | ||
|
||
for _, w := range options.Workspace { | ||
workspace := &asana.Workspace{ID: w} | ||
check(ListProjects(client, workspace)) | ||
} | ||
return | ||
} | ||
|
||
for _, p := range options.Project { | ||
project := &asana.Project{ID: p} | ||
|
||
if options.AddSection != "" { | ||
request := &asana.SectionBase{ | ||
Name: options.AddSection, | ||
} | ||
|
||
_, err := project.CreateSection(client, request) | ||
check(err) | ||
return | ||
} | ||
|
||
fmtProject(client, project) | ||
} | ||
return | ||
} | ||
|
||
for _, t := range options.Task { | ||
task := &asana.Task{ID: t} | ||
check(task.Fetch(client)) | ||
|
||
fmt.Printf("Task %s: %q\n", task.ID, task.Name) | ||
if options.Attach != "" { | ||
addAttachment(task, client) | ||
return | ||
} | ||
if options.Stories { | ||
listStories(task, client) | ||
} | ||
if options.Clean { | ||
cleanStories(task, client) | ||
} | ||
|
||
fmtTask(task, client) | ||
} | ||
if _, err := flags.Parse(&options); err != nil { | ||
return | ||
} | ||
|
||
// Create a client | ||
client := asana.NewClient(&http.Client{ | ||
Transport: &http.Transport{ | ||
Proxy: authenticate, | ||
}, | ||
}) | ||
if options.Debug { | ||
client.DefaultOptions.Debug = &True | ||
client.DefaultOptions.Pretty = &True | ||
} | ||
client.Verbose = options.Verbose | ||
client.DefaultOptions.Enable = []asana.Feature{asana.StringIDs, asana.NewSections, asana.NewTaskSubtypes, asana.ProjectPrivacySetting} | ||
|
||
// Load a task object | ||
if options.Task == nil { | ||
|
||
// Load a project object | ||
if options.Project == nil { | ||
|
||
// Load a workspace object | ||
if options.Workspace == nil { | ||
check(ListWorkspaces(client)) | ||
return | ||
} | ||
|
||
for _, w := range options.Workspace { | ||
workspace := &asana.Workspace{ID: w} | ||
check(ListProjects(client, workspace)) | ||
} | ||
return | ||
} | ||
|
||
for _, p := range options.Project { | ||
project := &asana.Project{ID: p} | ||
|
||
if options.AddSection != "" { | ||
request := &asana.SectionBase{ | ||
Name: options.AddSection, | ||
} | ||
|
||
_, err := project.CreateSection(client, request) | ||
check(err) | ||
return | ||
} | ||
|
||
fmtProject(client, project) | ||
} | ||
return | ||
} | ||
|
||
for _, t := range options.Task { | ||
task := &asana.Task{ID: t} | ||
check(task.Fetch(client)) | ||
|
||
fmt.Printf("Task %s: %q\n", task.ID, task.Name) | ||
if options.Attach != "" { | ||
addAttachment(task, client) | ||
return | ||
} | ||
if options.Stories { | ||
listStories(task, client) | ||
} | ||
if options.Clean { | ||
cleanStories(task, client) | ||
} | ||
|
||
fmtTask(task, client) | ||
} | ||
} | ||
|
||
func listStories(task *asana.Task, client *asana.Client) { | ||
stories, _, _ := task.Stories(client) | ||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
|
||
for _, s := range stories { | ||
fmt.Printf("Story %s (%s):\n", s.ID, s.CreatedBy.Name) | ||
check(enc.Encode(s)) | ||
} | ||
stories, _, _ := task.Stories(client) | ||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
|
||
for _, s := range stories { | ||
fmt.Printf("Story %s (%s):\n", s.ID, s.CreatedBy.Name) | ||
check(enc.Encode(s)) | ||
} | ||
} | ||
|
||
func cleanStories(task *asana.Task, client *asana.Client) { | ||
stories, _, _ := task.Stories(client) | ||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
stories, _, _ := task.Stories(client) | ||
enc := json.NewEncoder(os.Stdout) | ||
enc.SetIndent("", " ") | ||
|
||
for _, s := range stories { | ||
check(s.Delete(client)) | ||
} | ||
for _, s := range stories { | ||
check(s.Delete(client)) | ||
} | ||
} | ||
|
||
func fmtProject(client *asana.Client, project *asana.Project) { | ||
fmt.Println("\nSections:") | ||
check(ListSections(client, project)) | ||
fmt.Println("\nTasks:") | ||
check(ListTasks(client, project)) | ||
fmt.Println("\nSections:") | ||
check(ListSections(client, project)) | ||
fmt.Println("\nTasks:") | ||
check(ListTasks(client, project)) | ||
} | ||
|
||
func fmtTask(task *asana.Task, client *asana.Client) { | ||
fmt.Printf(" Completed: %v\n", task.Completed) | ||
if task.Completed != nil && !*task.Completed { | ||
fmt.Printf(" Due: %s\n", task.DueAt) | ||
} | ||
if task.Notes != "" { | ||
fmt.Printf(" Notes: %q\n", task.Notes) | ||
} | ||
// Get subtasks | ||
subtasks, nextPage, err := task.Subtasks(client) | ||
check(err) | ||
_ = nextPage | ||
for _, subtask := range subtasks { | ||
fmt.Printf(" Subtask %s: %q\n", subtask.ID, subtask.Name) | ||
} | ||
fmt.Printf(" Completed: %v\n", task.Completed) | ||
if task.Completed != nil && !*task.Completed { | ||
fmt.Printf(" Due: %s\n", task.DueAt) | ||
} | ||
if task.Notes != "" { | ||
fmt.Printf(" Notes: %q\n", task.Notes) | ||
} | ||
// Get subtasks | ||
subtasks, nextPage, err := task.Subtasks(client) | ||
check(err) | ||
_ = nextPage | ||
for _, subtask := range subtasks { | ||
fmt.Printf(" Subtask %s: %q\n", subtask.ID, subtask.Name) | ||
} | ||
} | ||
|
||
func addAttachment(task *asana.Task, client *asana.Client) { | ||
f, err := os.Open(options.Attach) | ||
check(err) | ||
defer f.Close() | ||
a, err := task.CreateAttachment(client, &asana.NewAttachment{ | ||
Reader: f, | ||
FileName: f.Name(), | ||
ContentType: mime.TypeByExtension(filepath.Ext(f.Name())), | ||
}) | ||
check(err) | ||
fmt.Printf("Attachment added: %+v", a) | ||
f, err := os.Open(options.Attach) | ||
check(err) | ||
defer f.Close() | ||
a, err := task.CreateAttachment(client, &asana.NewAttachment{ | ||
Reader: f, | ||
FileName: f.Name(), | ||
ContentType: mime.TypeByExtension(filepath.Ext(f.Name())), | ||
}) | ||
check(err) | ||
fmt.Printf("Attachment added: %+v", a) | ||
} |
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.