How do I trigger a command block by giving an item to a villager?

Its better to try and find out yourself, but anyway:

/summon villager ~ ~1 ~ {Profession:1,Career:1,CareerLevel:100,Offers:{Recipes:[{rewardExp:1b,maxUses:1,uses:0,buy:{id:pumpkin,Count:1b,tag:{display:{Name:"The great pumpkin"}}},sell:{id:end_rod,Count:1b,tag:{display:{Name:"Quest Complete!"}}}}]}}

What this will do is summon a villager that will trade one pumpkin called "The great pumpkin" for one end rod called "Quest complete". This trade will reward XP orbs, meaning that it will spawn a small amount of XP orbs when the trade is completed. In order to find out if the player traded yet, do something along these lines:

Repeating commandblock:

/testfor @e[type=xp_orb,r=1,x=<x>,y=<y>,z=<z>

Replace , and with the coordinates of the villager. And then a conditional chained commandblock after the repeating one with someting like:

/tellraw @a {"text":"Quest Complete!","color":"gold","bold":true}

What this will do is test for the xp_orbs that get spawned when the trade is completed, and then say in the chat: Quest Complete, in bold and in a gold color.

Alternativly, if the player has no option to get an endrod anywhere else use this in a repeating commandblock:

/clear @a minecraft:end_rod 

And then in a conditional chained commandblock:

/tellraw @a {"text":"Quest Complete!","color":"gold","bold":true}

What this will do is clear endrods out of the players inventory, and if the game finds an endrod and clears it, it means that the player finished the trade, so it says quest complete.